In our previous post we went through the steps to Setup a Docker Container With MongoDB manually.
Docker has a simple DSL that lets you automate all of these steps to make a conainer.
Docker file syntax
Every line in a docker file has the following structure:
Comments are ignored, and the first line in the docker file should contain the command
Commands available full details
- FROM (select the base image)
- MAINTAINER (Set the author field for images)
- RUN (run a command, and commit)
- CMD (the default execution command for the container)
- EXPOSE (set the port to be publicly exposed)
- ENV (set environment variables)
- ADD (add files from source and copy them to the container)
- ENTRYPOINT (configure the container to run as an executable)
- VOLUME (add a volume)
- USER (set the user)
- WORKDIR (set working directory)
We create a dockerfile, and just use all the same commands we used previously
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Then we issue:
sudo docker build -t codiez/mongodb .
and start it up with…
sudo docker run -d codiez/mongodb
In the next post, we will discuss creating a SAAS database service using docker and mongodb.