Skip to main content

CRI - Docker

Installation#

docker-installation.yaml
---
- hosts: all
become: yes
tasks:
- name: purge
apt:
name: '{{ item }}'
state: absent
update_cache: yes
loop: ['docker', 'docker-engine', 'docker.io', 'containerd', 'runc']
- name: install required
apt:
name: '{{ item }}'
state: latest
update_cache: yes
loop: ['apt-transport-https', 'ca-certificates', 'curl', 'gnupg']
- name: add docker GPG apt key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
keyring: /usr/share/keyrings/docker-archive-keyring.gpg
- name: add docker repository
apt_repository:
repo: deb
[arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]
https://download.docker.com/linux/ubuntu
{{ ansible_distribution_release }} stable
filename: docker
- name: install docker
apt:
name: '{{ item }}'
state: latest
update_cache: yes
loop: ['docker-ce', 'docker-ce-cli', 'containerd.io']
- name: set cgroupdriver to systemd
copy:
dest: '/etc/docker/daemon.json'
content: |
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
- name: systemd enable docker
ansible.builtin.systemd:
name: '{{ item }}'
enabled: yes
state: started
loop: ['docker', 'containerd']
- name: systemd daemon-reload
ansible.builtin.systemd:
daemon_reload: yes

Commands#

run#

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

-it ์˜ต์…˜์ด ๋งŽ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

  • --interactive
  • --tty

pull, create, start, attach#

docker create ๋˜๋Š” docker run์„ ์‹คํ–‰ํ–ˆ์„ ๋•Œ, ์ด๋ฏธ์ง€๊ฐ€ ์—†๋‹ค๋ฉด docker pull ๋ช…๋ น์–ด๋กœ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

docker run -it == docker create -it -> docker start -> docker attach

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
docker start [OPTIONS] CONTAINER [CONTAINER...]
docker attach [OPTIONS] CONTAINER

ps#

docker ps [OPTIONS]
  • -a | --all: ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์€ ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋งŒ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

inspect#

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

๋„์ปค ์˜ค๋ธŒ์ ํŠธ์˜ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

stop#

docker stop [OPTIONS] CONTAINER [CONTAINER...]

rm#

docker rm [OPTIONS] CONTAINER [CONTAINER...]

rmi#

docker rmi [OPTIONS] IMAGE [IMAGE...]

Dockerfile#

Reference#

Last updated on