Post

Docker commands

✅ create image, container and run container

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- create image, container and run container
docker run nginx
docker run mysql

-- run docker in background
run nginx -d nginx

-- name container
docker run -d --name my-web-server nginx

-- run container in a certain port
-- host port: 4000, (localhost:4000으로 접속)
-- container port: 80
docker run -d -p 4000:80 nginx

-- get running containers
docker ps

-- get all containers
docker ps -a

✅ Image commands

  • can download images in dockerhub.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- download image
docker pull nginx

-- get image, check downloaded image
docker image ls

-- delete image
docker image rm 

-- force delete image
docker image rm -f 

-- delete all images
docker image rm $(docker images -q)

✅ Container commands

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
-- create container
docker create nginx
docker create mysql

-- get all created containers
docker ps -a

-- start the container
-- now ps -a STATUS would be "up"
docker start 

-- stop container
docker stop 

-- force stop container
docker kill 

-- remove stopped container
docker rm 

-- delete all containers
docker rm $(docker ps -qa)

-- stop and remove container
docker rm -f 

✅ Logs

1
2
3
4
5
6
7
8
9
10
11
-- read logs
docker logs 

-- tail read logs
docker logs --tail 10 

-- read live logs
docker logs -f 

-- read live logs of tail
docker logs --tail 0 -f 

✅ container 접속하기

1
docker exec -it {containerID}} bash

This post is licensed under CC BY 4.0 by the author.