You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docker image tag mysql:5 test:latest
docker image push test:latest
image build (-t: tagging image name)
docker image build -t hello . (run this command where “Dockerfile” is)
(PS: image file name MUST be “Dockerfile”, no extension)
image save and load (t=tag, i=input, o=output)
docker save -o <path for created tar file> <image name>
docker save -o [imageName].tar [imageName]
docker load -i <path to docker image tar file>
docker load -i .\[imageName].tar
env, copy from container to host
docker container run --net host [imageName]
ENV USER="space"
docker container run -d -d p 80:80 --name hd2 -e USER="UserName" [imageName]
docker cp host_path:/usr/src/app .
multistage image File
FROM mcr.microsoft.com/java/jdk:8-zulu-alpine AS compiler
COPY --from=compiler /usr/src/app .
COPY --from=nginx:latest /usr/src/app .
using ARG (ARG=argument is only used while creating image, difference from ENV: env is reachable from container)
docker-compose commands (run this command where “docker-compose.yml” is)
docker-compose up -d
docker-compose ps
docker container ls -a
docker-compose down
docker-compose config
docker-compose images
docker-compose logs
docker-compose exec websrv ls -al
docker-compose build
docker swarm commmunication
In server, these ports should be opened:
- TCP port 2377 (Cluster management)
- TCP - UDP port 7946 (Communication between nodes)
- UDP port 4789 (Overlay network)
creating docker swarm: binding manager and worker nodes (test it with docker play with creating instances on docker play environment)
(PS1: To login PlayWithDocker, you must sign up Docker Hub to use PlayWithDocker)
(PS2: On PlayWithDocker Paste: Shift+Insert, Copy: CTRL+Insert)
docker swarm init --advertise-addr 192.168.0.13 (after choosing manager node, run this command to initialize swarm, IP is the master node’s IP)
(after running command above, following writings appear on master PC to add worker PCs)
Swarm initialized: current node (u4tqju429dcmggxmw29ll8nls) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1 5qbi2uydkawpcuo9rcp4quytr37z1 pzob5ss66o821br09h7x9-3jrqc08scyetlxg9iyhck25u1 192.168.0.13:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
(run following command on worker nodes)
docker swarm join --token SWMTKN-1 5qbi2uydkawpcuo9rcp4quytr37z1 pzob5ss66o821br09h7x9-3jrqc08scyetlxg9iyhck25u1 192.168.0.13:2377
(if you want to add more manager nodes to swarm cluster, run following command on manager PC to take manager token from master PC)
docker swarm join-token manager
(after running command above, following writings appear on master PC to add manager PCs)
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1 5qbi2uydkawpcuo9rcp4quytr37z 1pzob5ss66o821br09h7x9-3bv78968l9qdfza68979np715 192.168.0.13:2377
This node joined a swarm as a manager
(run following command on manager nodes)
docker swarm join --token SWMTKN-1 5qbi2uydkawpcuo9rcp4quytr37z 1pzob5ss66o821br09h7x9-3bv78968l9qdfza68979np715 192.168.0.13:2377
list managers and workers on swarm
docker node ls
docker service, ls
(run these commands on manager nodes)
docker service (to see docker service help)
docker service create --name test --replicas=5 -p 8080:80 nginx
docker service ps test (shows containers, which containers run on which PC)
docker service ls (list service, shows service detail)
docker service logs test
docker service scale test=3 (desired state 3 replica)
docker service rm test
docker service create --name glb --mode=global nginx
create overlay network
docker network create -d overlay over-net (creating overlay network)
docker service create --name webserv --network over-net -p 8080:80 --replicas=3 omerbsezer/sample-web-php
docker service create --name db --network over-net omerbsezer/sample-web-mysql
update service, rollback (update containers)
docker service update --help
docker service update -d --update-delay 5s --update-parallelism 2 --image omerbsezer/sample-web-php:v2 websrv (when updating images with version2, updating from 2 parallel branches)
docker service ps websrv
docker service rollback -d websrv (rollback to last status of websrv)
secret (to work with secrets, swarm mode must be active)
notepad or nano username.txt (create username.txt that include username)
notepad or nano password.txt (create password.txt that include password)
docker secret create username .\username.txt (create username secret object)
docker secret create password .\password.txt
docker secret inspect password
docker secret ls
docker service create -d --name secrettest --secret username --secret password omerbsezer/sample-web-php
docker service ps secrettest
docker ps
docker exec -it c4c sh
(when we are in the container, we can reach and see secrets at “/run/secrets”)
(when new password is needed, new password file must be created again)
echo "password222" | docker secret create password2
docker service update --secret-rm password --secret-add password2 secrettest (password is removed, new password2 object is added)
docker stack (stack is like compose, but run-on swarm)(deploy, replica, update-config definitions are added to define Docker Stack file)