Professional Documents
Culture Documents
- pull image
- start image in same window(logs in the current window)
docker run -d <image-name>:<version | default : latest>
- pull image
- start image in detach mode (no logs in the current window)
docker run -p<host-port-number>:<container-port-number> <image-name>:<version |
default : latest>
-to bind(map) host machine port to container port
docker pull <image-name>:<version | default : latest>
- pull image to local host
docker ps
- list of all running container
docker stop <container id>
- stop that container
docker start <container id>
- start that container again
docker ps -a
- history of all container ran so far
docker images
-list of all available docker images locally
docker logs <container-id>
- check logs inside a container (running image logs)
docker logs <image-custom-name> (This is not image name)
- check logs inside a container (running image logs)
docker logs <container-id> | tail
- | tail will show latest part of the logs only
docker logs <container-id> -f
- -f will stream the real time logs in the console
Note : use 'exit' command to get out from container terminal to host terminal
docker network ls
- list of all available docker network
docker network create <custom-network-name>
- create a new docker network of our own
[FYI] Docker network help to communicate multiple container with each other
version:3
services:
mongodb: (this is <custom-container-name>)
image:mongo (acctual image name)
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
volumes:
- <custom-volume-name>:<directory-path-of-the-container>
mongo-express: (this is <custom-container-name>)
image: mongo-express (acctual image name)
ports:
- 8081:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=<custom-container-name-of-mongo>
volumes:
<custom-volume-name>:
driver: local
[FYI] above contect saved in a .yaml file is equivalent with above two command.
This will automatically creates network and assign them into it,
so no need to create seperate network.
container can't persist data, once container stop / deleted all data removed, to
persist data we
use volumes to store container data into local file system.
FROM node:13-alpine
ENV MONGO_DB_USERNAME=admin \
MONGO_DB_PWD=password
RUN mkdir -p /home/app [ this will create a folder app inside container]
COPY ./source /home/app [ this will copy everything from source folder in host
machine to app folder in container]
CMD ["node", "/home/app/server.js"]
- Dockerfile must be saved name as Dockerfile and it's a simple text file.
- FROM command is used for base layer of the image
- ENV is for setting environment variable to the container
- RUN is to run any linux command that will executed inside container
- COPY is used to copy files from host machine to container
- CMD is where we mentioned the entry point of the exceutions