Список запущенных (работающих) контейнеров
docker ps
Список всех контейнеров в системе (в любом состоянии)
docker ps -a
Посмотреть логи контейнера ’myexample’
docker logs myexample
Запустить контейнер вручную
docker start myexample
Остановить контейнер вручную
docker stop myexample
Если контейнер находится в состоянии Exited, вы можете получить причину выхода с помощью команды:
docker inspect --format='{{.State.ExitCode}}' pigallery2
docker inspect pigallery2 | grep -i error
Если код выхода не равен 0, это значит, что произошла ошибка.
docker run -it --rm \
-v /srv/dev-disk-by-uuid-2caf2535-01a9-44ee-b74c-455edd9ee987/docker/composefiles/FotoGalleryia:/FotoGalleryia/config \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/db-data:/FotoGalleryia/db \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/images:/FotoGalleryia/images \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/tmp:/FotoGalleryia/tmp \
bpatrik/pigallery2
docker run \
-p 8186:80 \
-e NODE_ENV=debug \
-v /srv/dev-disk-by-uuid-2caf2535-01a9-44ee-b74c-455edd9ee987/docker/composefiles/FotoGalleryia:/FotoGalleryia/config \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/db-data:/FotoGalleryia/db \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/images:/FotoGalleryia/images \
-v /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/tmp:/FotoGalleryia/tmp \
bpatrik/pigallery2:latest
КОНФИГ
services: pigallery2: image: bpatrik/pigallery2:latest container_name: pigallery2 environment: - PUID=1005 - PGID=100 - TZ=Europe/Chisinau - NODE_ENV=debug #production # set to 'debug' for full debug logging volumes: - /srv/dev-disk-by-uuid-2caf2535-01a9-44ee-b74c-455edd9ee987/docker/composefiles/FotoGalleryia:/FotoGalleryia/config - /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/db-data:/FotoGalleryia/db - /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/images:/FotoGalleryia/images - /srv/dev-disk-by-uuid-9b3771d9-c454-4acd-b683-568da8815820/FotoGalleryia/tmp:/FotoGalleryia/tmp ports: - 8186:80 restart: no
Добавить UMASK
По-умолчанию файлы, которые будут приходить на HDD из сервисов в контейнерах, помечены правами юзера, который рулит докером — mydoker, и права на них установлены так
-rw-r--r--, что в числовом виде 644.
4 — для группы (r--): только чтение.
4 — для остальных (r--): только чтение.
Сделаем так, чтобы юзер mydoker из сервиса в контейнере создавал файлы с правами 770.
4 — для группы (rwx): чтение и запись и выполнение.
4 — для остальных (---): нет доступа.
Это можно сделать через настройку umask в каждом контейнере, который будет создан через Docker Compose
services:
your_service:
environment:
- UMASK=007
Учесть, что иногда службы в контейнерах могут перезаписывать значение umask.
Добавить ssh в Docker
After running through the commands above let’s test out how to use ssh when connecting to a docker container. For this example we will begin by creating the following docker compose file.
version: '3.9'
services:
ports:
- USER\_NAME=user
aliases:
This example uses the linuxserver/openssh-server docker image. The image uses port 2222 and supports the following environment variables to make the ssh docker container function as desired.
\item PUBLIC\_KEY – The location of the public key to be copied to the server. The matching private key can then be used for the authentication.
\item PASSWORD\_ACCESS – The default is false, but we will run through an example of using ssh when password access is allowed.
\item USER\_PASSWORD – The password for the user connecting with ssh.
\item USER\_NAME – The user that will be connecting to the ssh server.
\end{itemize}
After running docker-compose up --build you can ssh into the running container with the following command:
ssh -p 2222 user@172.21.0.10
Note that port 22 is the default port for the ssh command, so in this case it has to be explicitly stated by using the -p 2222 option.
docker ssh password
To test the openssh docker container with an ssh key instead of a password, remove the USER\_PASSWORD and PASSWORD\_ACCESS variables. Make sure to include your public key in the config/.ssh/authorized\_keys directory that is mounted. After a successful test you should see the following result.
docker ssh key
In testing this docker container you may run across the following error:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:EgScdNs2FNfQxc3BTGXjI+6f/S6+XUNan6zIgHhZ94Q.
Please contact your system administrator.
Add correct host key in /home/misterpki/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/misterpki/.ssh/known_hosts:1
remove with:
ssh-keygen -f "/home/misterpki/.ssh/known_hosts" -R "[172.21.0.10]:2222"
ECDSA host key for [172.21.0.10]:2222 has changed and you have requested strict checking.
Host key verification failed.
This “Host key verification failed” error happens when the host key has changed on the openssh server. For this test, simply follow the instructions to remove the already trusted key from the known\_hosts file. If this error is encountered in the wild, first make sure to verify the host key change was valid and not malicious before proceeding.
Удалить контейнер
docker ps -a
См. в результатах CONTAINER ID
Принудительная остановка и удаление (можно удалить несколько подряд):
docker rm -f 123abc 456qwe
Next step: Импорт контейнеров