Skip to Content
We've released a new docs site! 🎉
TemplateHostingRun the template in a Docker container

How to run Sharetribe Web Template in a Docker container

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 learn more about Docker and its key concepts, check out Docker documentation  or watch a Docker introduction video . This guide assumes you have Docker installed and running on your development machine.

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.

Last updated on