Docker install
docker
источник: Install Docker Engine on Ubuntu
только важные выдержки
Категория: Программирование. Направление: Bash. Группа: Docker.
Добавлено: 07-03-2025. Обновлено: 30-08-2025
Ключи: #docker
Установка docker в ubuntu:
Install Docker Engine on Ubuntu >>
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
или
sudo gnome-terminal
# Add Docker's official GPG key:
apt-get update
apt-get install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
Result:
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/
Commands:
docker images # all installed images
docker start ubuntu # load and run image ubuntu:latest
docker ps # show runing containers
docker ps -a # show all containers
docker run -it ubuntu # run image ubuntu --interactive --terminal
exit # exit from ubuntu
docker run -d -it ubuntu # run image with detach
docker attach 87cb359fc211 # auuach to runing container
docker start 87cb359fc211 # start container
docker stop 87cb359fc211 # stop container
Exemple: run nginx
docker run -d -p8888:80 nginx
docker ps
CONTAINER_ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES |
---|---|---|---|---|---|---|
9752c4b62a15 | nginx | "/docker-entrypoint.…" | 10 seconds ago | Up 9 seconds | 0.0.0.0:8888->80/tcp, [::]:8888->80/tcp | fervent_cohen |
docker attach 9752c4b62a15
# Ctrl+Q
Create docker file
./index.html
<h1>Hello World -- Docker Nginx</h1>
./Dockerfile
FROM nginx:latest
WORKDIR /user/share/nginx/html
COPY index.html .
docker build . -t nginx-hello-world
docker images
docker run -d -p9999:80 nginx-hello-world
# from local :9999 to :80 in container
docker ps
docker exec -it f384cccb1ee1 sh # run container with shell
docker start -ai f384cccb1ee1 # start with attach -a interact -i
Docker with python
Create dir app. Create in dir files Dockerfile, main.py
./app/Dockerfile
FROM python:alpine
WORKDIR /app_pjs
RUN pip install pymongo
COPY . .
CMD ["python", "src/main.py"]
./app/main.py
from pymongo import MongoClient
from pprint import pprint
MONGO_URL = "mongodb://mongo:27017"
client = MongoClient(MONGO_URL)
db = client.admin
dbs_list = db.command("listDatabases")
pprint(dbs_list)
Docker Compose
Move ./Dockerfile and ./src to dirrectory ./app
Create ./docker-compose.yml
version: '3'
services:
app:
build: ./app
mongo:
image: mongo
Run docker compose:
# docker-compose up
docker compose up
If you catch error like this:
WARNING: MongoDB 5.0+ requires a CPU with AVX support, and your current system does not appear to have that!
Try next in yaml file:
mongo:
image: mongo:4.4.18
and repeat docker compose up
Remove all stoped containers:
docker container prune
docker image prune # remove all images
# remove volumes containers images and network of this project
docker compose down -v --rmi all --remove-orphans
docker compose up # start yaml project
docker compose down # stop and remove containers
Rebuild
docker compose up -d --build
Logs
docker logs 168f5ac4de49
# log of app container from docker compose