Warning
You are viewing the technical documentation for the Sharetribe Developer Platform. If you are looking for our no-code documentation, see our new help center.

Last updated

How to run Sharetribe Web Template in a Docker container

This guide describes how to set up a Docker container running the Sharetribe Web Template.

Table of Contents

Depending on your deployment infrastructure, you may want to run your Sharetribe Web Template based marketplace application in a Docker container. This article features a sample Dockerfile you can use to create your Docker image.

To run your template app with Docker, you will need to

  • add your Dockerfile
  • build the Docker image, and
  • run the Docker container.

Add your Dockerfile

For creating a Docker image of your template application, you will need to add a Dockerfile. Add a file titled Dockerfile with no file extension to the root of your template folder, on the same level as your package.json file. Copy the following contents, paste them to the newly created Dockerfile and save.

FROM node:16
WORKDIR /home/node/app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
COPY . .
ENV PORT=4000
ENV NODE_ENV=production
EXPOSE 4000
RUN yarn run build
USER node
CMD ["yarn", "start"]

In addition, you need to add a .dockerignore file in the same root folder. Copy the following contents, paste them to the newly created .dockerignore file, and save.

# Ignore node_modules because they get installed in the Dockerfile.
node_modules

Build your Docker image and run the Docker container

To build your Docker image, open your command line and navigate to the root of your template folder. Run the following command – be careful to include the final . , as it indicates that the Dockerfile is in the current directory.

$ docker build -t sharetribe-docker .

The build step can take a while. After the build step completes, you can start a container using the image you created.

$ docker run -dp 4000:4000 sharetribe-docker

You can now visit http://localhost:4000 on your local machine to see that the container is running your application.