-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter-6
35 lines (27 loc) · 2.64 KB
/
Chapter-6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Docker Common Commands
----------------------
docker pull - Pull the docker image from docker repository.
docker ps - List all running containers.
docker images - List all docker images you have locally.
docker stop [DOCKER_CONTAINER_ID] - Stop the running docker container having id DOCKER_CONTAINER_ID.
docker run [IMAGE_NAME] - Runs a docker image in non-detached mode.
docker run -d [IMAGE_NAME] - Runs a docker image in detached mode.
docker ps -a - List info of all containers which are running or not running.
docker run -p[HOST_PORT]:[CONTAINER_PORT] -d [IMAGE_NAME] - Create a container in detached mode and create a port binding b/w host port and container port and starts the container.
docker start [CONTAINER_ID] - To Start a stopped container.
docker network ls - List all the docker networks (autogenerated also along with the ones you created).
docker network create [NETWORK_NAME] - Creates a new docker network.
[IMPORTANT]
------------
=> docker logs [CONTAINER_ID] - To get the logs of the container whose id is specified in the command.
OR
=> docker logs [CONTAINER_NAME]
=> docker run -p[HOST_PORT]:[CONTAINER_PORT] -d --name [CONTAINER_NAME] [IMAGE_NAME] - Create a container in detached mode and create a port binding b/w host port and container port and starts the container and provide the name given in --name argument to the container.
=> docker run -p[HOST_PORT]:[CONTAINER_PORT] -d -e [ENVIRONMENT_VARIABLE_NAME]=[ENVIRONMENT_VARIABLE_VALUE] -e [SECOND_ENVIRONMENT_VARIABLE_NAME]=[SECOND_ENVIRONMENT_VARIABLE_VALUE] --name [CONTAINER_NAME] [IMAGE_NAME] --net [DOCKER_NETWORK_NAME] - This will start docker in detached mode as previous command but it also sets some environment variables and make this docker available in the network name specified in --net arguments.
=> docker exec -it [CONTAINER_ID] OR [CONTAINER_NAME] /bin/bash - To get interactive bin bash terminal of a running container.
=> Difference b/w docker run and docker start command is that, docker run work with images and create a brand new container, but docker start command does not work with images, it is used to restart the stopped container with all predefined values like name of container, port binding all previously used.
Example practical commands for docker
(For setting up mongodb container)
=> docker run -p 27017:27017 -d -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password --name mongodb --net mongo-network mongo
(For setting up mongo-express container)
=> docker run -d -p 8081:8081 -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin -e ME_CONFIG_MONGODB_ADMINPASSWORD=password -e ME_CONFIG_MONGODB_SERVER=mongodb --name mongo-express --net mongo-network mongo-express