While I used Amazon ECS, the same applies to Docker running on any host from local to another hosted provider.
The base image here was for NodeJS, however, any other Alpine based distribution will work just as well.
The first step is to create your Dockerfile. First, we add the edge repositories to the base Node image and then we use apk to install Chromium and all the required dependencies.
As I was using puppeteer in NodeJS, which typically downloads its own version of Chromium, we use the PUPPETEER_SKIP_CHROMIUM_DOWNLOAD variable to tell puppeteer that we wish for it to skip this process.
# Dockerfile
FROM node:8.11.1-alpine
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
Once you have created your Dockerfile the next step is to build the image. We can use the docker command line tool here to build the image for us. Specify a tag for your image after the -t parameter.
docker build -t docker-chromium .
Sending build context to Docker daemon 344.8 MB
Step 1/14 : FROM node:8.11.1-alpine
---> e707e7ad7186
Step 2/14 : RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
---> Using cache
---> 557bab3760cd
Step 3/14 : RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
---> Using cache
---> 8c46e4f2ffa4
Step 4/14 : RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
The first time you run the build you will see a little more output than this as the required dependencies are downloaded.
The final step now is to run your Docker container. If you wish to test this locally you can simply issue the docker run command. If you wish to forward any ports you can use the -p command for this.
docker run -p 3000:3000 docker-chromium
[2018-07-07 02:58:11] PM2 log: Launching in no daemon mode
[2018-07-07 02:58:12] PM2 log: Starting execution sequence in -fork mode- for app name:sumo-microsumo-mogul-csv id:0
That’s it! Now your Docker container is running and you can connect to your application via http://localhost:3000/
Damian Hodgkiss
Senior Staff Engineer at Sumo Group, leading development of AppSumo marketplace. Technical solopreneur with 25+ years of experience building SaaS products.
Creating Freedom
Join me on the journey from engineer to solopreneur. Learn how to build profitable SaaS products while keeping your technical edge.
Proven strategies
Learn the counterintuitive ways to find and validate SaaS ideas
Technical insights
From choosing tech stacks to building your MVP efficiently
Founder mindset
Transform from engineer to entrepreneur with practical steps