docker第一阶段:入门

1. docker install:
1.1 docker install repository:
1.1.1 install related package:

sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

1.1.2 install gpg key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

1.1.3 install to sources.list

echo \
"deb [arch=$(dpkg --print-architecture) 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

1.2 docker install docker engine:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io


2. docker configure:

sudo groupadd docker
sudo usermod -aG docker $(whoami)
sudo service docker start
sudo chmod 666 /var/run/docker.sock


3. docker test run:
sudo docker run hello-world

4. docker command:
docker build, give the image a tag name:
docker build -t <tag name> .
example:
docker build -t ubuntu .

docker run:
docker run -t <tag name>

docker run in detach mode:
docker run -d <tag name>

docker run in detach mode, and bash wait in background:
docker run -t -d <tag name>

docker run, give the container a name:
docker run --name <container name> <tag name>

docker run, enter bash:
docker run -t -d --name <container name> <tag name>
docker exec -t -i <container name> /bin/bash
example:
docker run -t -d --name ubuntu ubuntu:18.04
docker exec -t -i ubuntu /bin/bash

view all container and images:
docker ps -a && docker images -a

remove all containers:
docker rm $(docker ps -aq) 

remove all images:
docker rmi $(docker images -q)

remove named container:
docker container rm <container name>

volume create :
docker volume create <volumn name>
docker volume inspect <volumn name>

volume --mount:
docker run --mount source=<volume name>,target=/usr/src/myapp <tag name>
volume --volume:
docker run --volume ~/Desktop/docker/docker_volume:/usr/src/ <tag name>
(failed to check files in ~/Desktop/docker/docker_volume)

volume check:
docker volume ls

volume visit:
cd /var/lib/docker/volumes/dockerVolume/_data

volume rm:
docker volume rm <volumn name>

reference:
https://stackoverflow.com/questions/30209776/docker-container-will-automatically-stop-after-docker-run-d




 
posted @ 2021-02-22 15:23  hkingsp  阅读(62)  评论(0编辑  收藏  举报