27
loading...
This website collects cookies to deliver better user experience
docker version
docker pull redis
docker images
docker image ls
docker run postgres:9.6
docker run docker/whalesay cowsay Hello World!
docker run -d postgres:9.6
docker attach ee8f2eb0b433
docker ps
docker ps -a
docker stop ee8f2eb0b433
docker run
. All configurations are restored which were set while running doc run
command.docker start ee8f2eb0b433
docker ps
displays the port the application is listening inside the container. To connect to this port inside the container, we need the IP the application is running in. Every Docker container gets an IP assigned by default. This is an internal IP and can only be accessed from the host machine. Users outside of the docker host cannot access using this IP. For this, we need to use the IP of the docker host and map a free port from the docker host to the container port. You can also run multiple instances of application and map them to different ports on the host machine.docker run -p6000:6379 redis
docker ps
.docker logs 777f0e06c4c
docker logs 777f0e06c4c | tail
docker run -d --name my-custom-name redis
-it
stands for interactive terminal. -i
maps the standard input of the host to the Docker container. -t
stands for pseudo terminal,which displays prompts from the terminal. Requires id/name of container. You can even navigate around the virtual file system, check logs, manage environment, etc.docker exec -it 777f0e06c4c /bin/sh
docker exec 777f0e06c4c cat /etc/hosts
docker network ls
docker network create my-network
docker run -d \
-p27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=password \
--name mongodb \
--net my-network \
mongo
docker run -d \
-p8081:8081 \
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
-e ME_CONFIG_MONGODB_ADMINPASSWORD=password \
--net my-network \
--name mongo-express \
-e ME_CONFIG_MONGODB_SERVER=mongodb \
mongo-express
-e
sets the required environment variables.docker inspect dreamy_hellman
version: '3'
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
ports:
- 8080:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb
depends_on:
- mongodb
docker-compose -f my-docker-compose-file.yaml up
docker-compose -f my-docker-compose-file.yaml down
Dockerfile
.FROM node
ENV MONGO_INITDB_ROOT_USERNAME=admin \
MONGO_INITDB_ROOT_PASSWORD=password
RUN mkdir -p /home/app
COPY . /home/app
WORKDIR /home/app
CMD ["node","server.js"]
FROM
image - build on a base imageENV
- set environment variablesRUN
- execute any Linux commands on the container environmentCOPY
- executes on the host. Copies file from host to the containerWORKDIR
- set current working directory so that you don't need to provide full path from /home.CMD
- executes an entry point. There can be multiple RUN commands, but only one CMD command. The command and parameters should be separate entries in the list.FROM ubuntu
CMD sleep 5
docker run sleeper sleep 10
, the sleep 10
will overwrite the command specified on CMD
. To provide custom arguments, use the ENTRYPOINT
command.FROM ubuntu
ENTRYPOINT ["sleep"]
docker run sleeper 10
will append the argument 10
to the list of ENTRYPOINT
. ENTRYPOINT
and CMD
. Both ENTRYPOINT
and CMD
should be specified in JSON format.FROM ubuntu
ENTRYPOINT ["sleep"]
CMD ["5"]
CMD
will be appended to ENTRYPOINT
. If arguments are provided, they will be appended to ENTRYPOINT
and the values on CMD
will be disregarded. You can also overwrite the whole entrypoint command usingdocker run --entrypoint somethine-else sleeper 10
docker build -t my-app:1.0 .
Dockerfile
docker images
. Image can be deleted if all containers built from the image are deleted.docker rmi e455275b486c
docker ps
.docker rm silly_gagarin
docker run -v /home/mount/data:/var/lib/mysql/data
/var/lib/docker/volumes/{hash}/_data
.docker run -v /var/lib/mysql/data
docker run -v name:/var/lib/mysql/data
version: '3'
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
volumes:
- my-volume:/data/db
mongo-express:
image: mongo-express
ports:
- 8080:8080
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb
volumes:
my-volume:
driver: local