@volkansengul
iletisim@volkansengul.com
Docker, aynı işletim sistemi üzerinde, yüzlerce hatta binlerce birbirinden izole ve bağımsız containerlar sayesinde sanallaştırma sağlayan bir teknolojidir
Fiziksel sunucu > Sanallaştırma > Hyper V > Linux Container
Sadece bir java uygulaması çalıştırmak istiyorum
Docker yok iken;
Sunucu > İşletim Sistemi > Java Runtime > Dependency > App
Docker yok ile;
* Java Runtime > Dependency > App
* işletim sistemi kernel'den bağımsız yine var
Image 'ın çalışan haline container denir :)
İzolasyon ve gerçek bağımsız paketler
2016 'dan beri kullanılabilir hale geldi.
- işletim sisteminin parçası bulunmaktadır
- process isolated & hyper-v isolated
Docker desktop
https://www.docker.com/products/docker-desktop/
* WSL tercih ediyorum.
* WSL 1 kurulu ise WSL 2 'ye güncellemem gerekiyor.
> docker version ( server yanıtı geldi mi kontrol ediniz )
> docker info
> docker run --help
> docker container run --help
> docker image push
> docker push
> docker run hello-world
> docker run -d -p 80:80 docker/getting-started
> docker ps * çalışan container listesi
> docker ps -a * tüm container listesi
> docker container run -- name merhaba hello-world
> docker rm a5b
> docker rm merhaba
> docker start b32
> docker logs merhaba
> docker run -d --name websunucu httpd
> docker ps ***
* -d : deattach
> docker rm websunucu
> docker rm -f websunucu
> docker stop websunucu
> docker run --name websunucu2 httpd date
> docker exec websunucu date
> docker exec -it websunucu sh / bash / powershell
* it : interactive terminal
* sh: shell
# pwd, hostname, ls, exit
> docker inspect websunucu
Pre-Container era *
# webserver1
linux > apache > index.html
# ax54asd4fasr
apache > index.html
* sürekli yaşamasını beklemiyorum
* sorun çözmekle uğraşma, yenisini yarat
* sorunu image 'da çözmeliyiz
1. Container'lar tek bir uygulama çalıştırmak için dizayn edilmiştir
2. Image dediğimiz objelerden oluşturulur, herşey image yaratma aşamasında çözülür. (dependency, kurulum vs )
3. Disposable 'dır. Sorun oluştuysa gözünün yaşına bakma
4. Immutable olmalıdır, değişiklik lazımsa yeni image ile yola devam edilmeli
writable layer of container
/bin /etc /lib /mnt /opt /root /sbin /sys
/usr /dev /media /proc /run /srv /tmp
/app/app1.py /test/test3.txt
Image (read only layers)
> docker exec -it websunucu sh
> nano test123.txt
STDIN(0) - STDOUT(1) - STDERR(2)
> date
> date lorem
> docker run hello-world
> docker run -d hello-world
> docker logs websunucu
> docker logs --tail 5 websunucu
> docker logs -f websunucu
> docker exec websunucu ps ??
> docker top websunucu
> docker exec websunucu htop ??
> docker stats websunucu
> docker stats
-- memory=
-- memory-swap
--cpus=
--cpuset-cpus=
> docker container run -d name limit_test --memory=256m --cpus="3" nginx
> docker container run -d name limit_test2 --memory=1g --cpuset="0-3" nginx
--env KEY=Value
--env-file file
> docker container run --name env_test --env KEY1=value --env database_server=test.db.com ubuntu:latest printenv
> docker container run --name env_test --env-file .\env.list ubuntu:latest printenv
1. Volume : local
2. Network: bridge host ipvlan macvlan null overlay
3. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
app1:latest
container1
container2
RW Layer
RW Layer
app.log
app.log
>docker container run --name test2 -it -v C:/Projects/docker:/app ubuntu sh
>docker volume ls
>docker volume create first_volume
>docker volume inspect first_volume
>docker container run --name test1 -it -v first_volume:/app ubuntu sh
container
eth0: 172.17.0.2
veth
docker0
eth0:192.168.0.2
- Bridge
- Host
- Macvlan
- None
- Overlay
eth0: 172.17.0.2
mybridge
eth0:192.168.1.2
db
eth0: 172.17.0.3
web
host
eth0: 192.168.0.2
eth0: 192.168.0.2
db
eth0: 192.168.0.2
web
host
eth0: 192.168.1.2
macvlan10
db
eth0: 192.168.2.2
web
host
eth0.10
eth0
eth0.20
macvlan20
external network
VLAN10
VLAN20
db
hostA
web
hostB
rabbit mq
hostC
external network
pets-overlay
:)
> docker network ls
> docker network inspect bridge
> docker network create --driver bridge first_network
> docker network create --driver=bridge --subnet=10.10.0.0/16 --ip-range=10.10.10.0/24 --gateway=10.10.10.10 second_network
> docker container run -it --network first_network busybox sh
> ifconfig
> docker network connect first_network test_container
> docker container run --publish host-post:container-port/tcp-or-udp
> docker container run -d --name webserver -p 5000:80 httpd
Docker Hub, Azure Container Registery, Github
> docker image ls * IMAGE ID, NAME
> docker image pull image_name:tag
> docker image push image_name:tag
> docker image build -t image_repository:tag
volkansengul/hello-app:latest
docker.io/volkansengul/hello-app:latest
FROM : base image (zorunlu değil)
RUN : çalıştırılacak komut
WORKDIR: çalışma dizini (yoksa yaratılır)
COPY: benim bilgisayarımdaki X dizinini workdir'a kopyala
CMD: çalıştırılacak komutlar ( container yaratılınca )
EXPOSE : port belirlemek için
HEALTHCHECK: sağlık kontrolü
> docker image build -t image_repository:tag .
FROM ubuntu:18.04
COPY ./app
RUN make /app
CMD python /app/app.py
FROM python:2.7-alpine
WORKDIR /app
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
ADD ./app
EXPOSE 80
CMD ["gunicorn","app:app","-b","0.0.0.0:80"]
FROM microsoft/windowsservercore
COPY ./app
CMD ["/app/Controller.exe","run"]
> docker image tag hello-world:latest volkansengul/hello-world:test
> docker push volkansengul/hello-world:test
> docker image build -t volkansengul/dockertest:latest -f Dockerfile .
@volkansengul
iletisim@volkansengul.com