Docker install on ubuntu
Setup the docker via Repository
1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
Error: WARNING: unsafe ownership on homedir β/home/user/.gnupgβ
$ sudo gpgconf --kill dirmngr
$ sudo chown -R $USER ~/.gnupg
2. Add Dockerβs official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3. Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.
$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
1. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2. Verify that Docker Engine is installed correctly by running the hello-world image.
$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Docker add & remove user authorization
add
$ sudo usermod -aG docker [your-user]
Remove
$ sudo deluser [your-user] docker
Remove Docker
# λ컀 ν¨ν€μ§ μ κ±°
$ sudo apt-get purge docker-ce
# μ΄λ―Έμ§, 컨ν
μ΄λ, λ³Όλ₯¨, μ¬μ©μ μ§μ μ€μ νμΌμ ν¨ν€μ§ μ κ±°λ‘ μ κ±° λμ§ μμ. λ³λ μ κ±° νμν¨.
$ sudo rm -rf /var/lib/docker
Docker Software
-
λ컀 μμ§(Docker Engine): νΉμ ν μννΈμ¨μ΄λ₯Ό λ컀 컨ν μ΄λλ‘ λ§λ€κ³ μ€ννκ² ν΄μ£Όλ λ°λͺ¬(Daemon)μ μλ―Έν©λλ€. λ컀 μμ§κ³Ό λ컀 ν΄λΌμ΄μΈνΈ μ¬μ΄μλ REST APIκ° μ¬μ©λ©λλ€. REST API μλ²μ μμ²μ 보λ΄λ κ²μ΄ λ컀 ν΄λΌμ΄μΈνΈμ λλ€.
-
λ컀 ν΄λΌμ΄μΈνΈ(Docker Client): λ컀 μμ§κ³Ό ν΅μ νλ μννΈμ¨μ΄λ‘ κ°λ°μκ° μ§μ μ΄μ©ν μ μμ΅λλ€. μλμ°(Window)/λ§₯(Mac)/리λ μ€(Linux)λ₯Ό μ§μν©λλ€. λ¬Όλ‘ μλμ°λ λ컀λ₯Ό μ¬μ©νκΈ°μ μ΅μ μ 쑰건μ΄κ³ , 리λ μ€κ° μ μΌ μ΅μμ 쑰건μ΄μ§λ§ λ컀λ 곡μμ μΌλ‘ μλμ°λ₯Ό μ λλ‘ μ§μνκ³ μμ΅λλ€.
-
λ컀 νΈμ€νΈ μ΄μ체μ (Docker Host OS): λ컀 μμ§μ μ€μΉν μ μλ μ΄μ체μ νκ²½μ μλ―Έν©λλ€. 64λΉνΈ 리λ μ€ μ»€λ λ²μ 3.10 μ΄μ νκ²½μ μλ―Ένκ³ , 32λΉνΈ νκ²½μμλ λ컀 μμ§μ΄ λμκ°μ§ μλλ΅λλ€. μ μ΄μ μ΄κΈ°μ λ컀 μ΄λ―Έμ§λ μ¬μ§μ΄ μ€μ§ μ°λΆν¬(Ubuntu) μ΄μ체μ μ μ©μ΄μμ΄μ. νμ¬λ μ°λΆν¬, CentOS, Debian, Fedora λ±μμ μ¬μ©ν μ μκ² λμμ§λ§μ.
-
λ컀 λ¨Έμ (Docker Machine): λ‘컬 λ° μκ²©μ§ μλ²μ λ컀 μμ§μ μ€μΉνκ³ , λ€μν νκ²½ μ€μ μ μλμΌλ‘ μνν΄μ£Όλ ν΄λΌμ΄μΈνΈλ₯Ό μλ―Έν©λλ€.
Docker commands
-
docker ps
: νμ¬ λμκ°κ³ μλ 컨ν μ΄λλ₯Ό νμΈνλ λͺ λ Ήμ΄μ λλ€. -
docker images
: νμ¬ λ컀 λ¨Έμ μ μ€μΉλ λ컀 μ΄λ―Έμ§λ₯Ό νμΈνλ λͺ λ Ήμ΄μ λλ€. -
docker --version
: λ컀 λ²μ νμΈ -
sudo docker info
: μμΈν λ²μ νμΈ docker run hello-world
: λ컀μμ ν¬λ‘μ° μλ(Hello World)λ₯Ό λμ°λ λͺ λ Ήμ΄μ λλ€. μ°λ¦¬ λμλ 보μ΄μ§ μμ§λ§ λ€μμ κ³Όμ μ΄ ν¬ν¨λλ κ²λλ€.- 곡μ μ¬μ΄νΈμμ install ν λ μΆλ ₯ν΄λ΄€μ.
docker images
: νμ¬ λ컀 λ¨Έμ μ μ‘΄μ¬νλ μ΄λ―Έμ§ λͺ©λ‘μ μΆλ ₯ν©λλ€.(base) yilgukseo ξ° ~/DL ξ° sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 4 months ago 13.3kB
docker ps -a
: νμ¬ λ컀 λ¨Έμ μ μ‘΄μ¬νλ 컨ν μ΄λλ₯Ό μΆλ ₯ν©λλ€.(base) yilgukseo ξ° ~/DL ξ° sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fad8e07c603f hello-world "/hello" 9 minutes ago Exited (0) 9 minutes ago eloquent_poincare
- ID, IMAGE, Command, CREATED, STATUS, PORTS, NAMES λ₯Ό νμΈ
-
docker rm (컨ν μ΄λ ID)
: νΉμ 컨ν μ΄λλ₯Ό μμ ν©λλ€. -
docker rm (컨ν μ΄λ ID) -f
: νΉμ 컨ν μ΄λλ₯Ό κ°μ λ‘ μμ ν©λλ€. docker run -it python
: νμ΄μ¬ μ΄λ―Έμ§λ₯Ό λ€μ΄λ‘λ λ°μμ μ€νν΄μ£Όλ λͺ λ Ήμ΄μ λλ€.-it
μ΅μ μ νμ€ μ μΆλ ₯μ μ΄μ©ν΄ 컨ν μ΄λμ λͺ λ Ήμ΄λ₯Ό μ λ ₯ν μ μκ² ν΄μ€λλ€.(base) yilgukseo ξ° ~/DL ξ° sudo docker run -it python Unable to find image 'python:latest' locally latest: Pulling from library/python 627b765e08d1: Pull complete c040670e5e55: Pull complete 073a180f4992: Pull complete bf76209566d0: Pull complete ca7044ed766e: Pull complete 7b16520e0e66: Pull complete e121e5a178df: Pull complete abbaf10bd160: Pull complete 4349f8e0b43a: Pull complete Digest: sha256:a465eb577326845a6772c0de37d11c4de3da9a0248c85ae8a7b8629561cb2185 Status: Downloaded newer image for python:latest Python 3.9.6 (default, Jul 22 2021, 15:16:20) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print("hellow docker python") hellow docker python
-
quit()
: νμ΄μ¬ μ½μμ μ’ λ£μν€λ λͺ λ Ήμ΄μ λλ€. -
docker start (컨ν μ΄λ ID)
: μ’ λ£λ 컨ν μ΄λλ₯Ό μ¬μμνλ λͺ λ Ήμ΄μ λλ€. -
docker attach (컨ν μ΄λ ID)
: νΉμ 컨ν μ΄λλ‘ μ¬μ μνλ λͺ λ Ήμ΄μ λλ€. -
docker exec -it (컨ν μ΄λ ID) bash
: μ€ν μ€μΈ 컨ν μ΄λμ λ°°μ(Bash) μλ‘ μ μνλ λͺ λ Ήμ΄μ λλ€. sudo docker stop container_id
: stop container(base) β yilgukseo ξ° ~/DL ξ° sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a645f33513a python "python3" 11 minutes ago Up About a minute busy_wescoff fad8e07c603f hello-world "/hello" 23 minutes ago Exited (0) 23 minutes ago eloquent_poincare (base) yilgukseo ξ° ~/DL ξ° sudo docker stop 0a645f33513a 0a645f33513a (base) yilgukseo ξ° ~/DL ξ° sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a645f33513a python "python3" 15 minutes ago Exited (137) 54 seconds ago busy_wescoff fad8e07c603f hello-world "/hello" 27 minutes ago Exited (0) 27 minutes ago eloquent_poincare
- stop νλ©΄
Exited
λΌκ³ νμλ¨.- startλ 빨리 λλλ° Stop μ μκ°μ΄ μ’ λ μμλ¨
- Container nameμΌλ‘λ λλμ§ νμΈ
- λ¨.
(base) yilgukseo ξ° ~/DL ξ° sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a645f33513a python "python3" 16 minutes ago Up 1 second busy_wescoff fad8e07c603f hello-world "/hello" 28 minutes ago Exited (0) 28 minutes ago eloquent_poincare (base) yilgukseo ξ° ~/DL ξ° sudo docker stop busy_wescoff busy_wescoff (base) yilgukseo ξ° ~/DL ξ° sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a645f33513a python "python3" 17 minutes ago Exited (137) 15 seconds ago busy_wescoff fad8e07c603f hello-world "/hello" 29 minutes ago Exited (0) 28 minutes ago eloquent_poincare
- λ¨.
- stop νλ©΄
-
docker rm [-option] [container ID]
: 컨ν μ΄λ μμ -
docker rm $(docker ps -a -q -f status=exited)
: μ€μ§λ 컨ν μ΄λ μμ docker rm $(docker ps -qa)
: λͺ¨λ 컨ν μ΄λ μμ
official docker commands: https://docs.docker.com/engine/reference/commandline/docker/
Appendix
Reference
Official site: https://docs.docker.com/engine/install/ubuntu/
https://shaul1991.medium.com/%EC%B4%88%EB%B3%B4%EA%B0%9C%EB%B0%9C%EC%9E%90-%EC%9D%BC%EC%A7%80-docker-%EC%84%A4%EC%B9%98%ED%95%B4%EB%B3%B4%EC%9E%90-d3d6a11ea098
https://unix.stackexchange.com/questions/452020/gpg-warning-unsafe-ownership-on-homedir-home-user-gnupg
ndb : https://ndb796.tistory.com/91
Leave a comment