A Dockerfile
is a text document that contains all the commands a user could call on the command line to assemble an image.
FROM node:alpine
LABEL author="Manh Tan"
ENV NODE_ENV=production
WORKDIR /var/www
COPY . .
RUN npm install
EXPOSE 3000
ENTRYPOINT ["node", "server.js"]
docker build -t <name> .
# Using Registry Name, Image Name and Tag
docker build -t <registry>/<name>:<tag>
docker push <user_name>/<image_name>:<tag>
docker run -p <externalPort>:<internalPort> <imageName>
docker logs <container_id>
docker run -p <ports> -v $(pwd)/var/www/logs <imageToRun>
docker network create
docker network ls
docker network rm [network]
# Running a database container in a network
docker run -d --net=isolated_network --name=mongodb mongo
docker run -d -p 3000:3000 -net=isolated_network --name=nodeapp imageName
docker exec -it <containerId> sh
- Start, stop and rebuild services
- View the status of running services
- Stream the log output of running services
- Run a one-off command on a service
docker-compose build
docker-compose up
docker-compose down
- YAML files are composed of maps and lists
- Identation matters
- Alway use spaces
- Maps:
- name: value pars
- Map can contains other maps for more complex data structures
- Lists:
- Sequence of items
- Multiple maps can be defined in a list
- build
- environment
- image
- networks
- ports
- volumes