https://docs.docker.com/engine/reference/run/
Running Docker in the Cloud
There are multiple ways of running docker in the cloud. This list is in order of management (cloud managed at the top)
Service | Control plane | Data plane | Inter-service network | multiple containers per host | Installation | Cost | ||
---|---|---|---|---|---|---|---|---|
Docker under a Cloud Managed Kubernetes service on Managed VM infrastructure | EKS Fargate | Managed | Managed | serverless | Managed | $144 US/month for control plane + EC2 cost | ||
Docker under a Cloud Managed Kubernetes service on client managed VM infrastructure | EKS EC2 | managed | unmanaged | yes | EC2 cost | |||
Docker under a Cloud Managed Docker service on Managed VM Infrastructure | ECS Fargate | managed | managed | serverless | ||||
Docker on ECS on EC2 instances (in a Auto Scaling Group) | ECS EC2 | managed | unmanaged | yes | EC2 cost + NLB | |||
Docker on Elastic Beanstalk | Elastic Beanstalk | managed | unmanaged | no | ||||
RKE Rancher Kubernetes Engine | EC2 | unmanaged | unmanaged | yes | RKE | |||
Docker on single EC2s | EC2 | unmanaged | unmanaged | yes | manual |
Running Docker in GCP - Google Kubernetes Engine
Running Docker in GCP - Cloud Run
Running Docker in GCP - Virtual Machine
Note: when running a container in docker and exposing a local port - do not use the -p flag after the container name:version - place all flags like -p -d double - name before
sudo apt install docker.io sudo docker ps sudo dpkg --configure -a sudo apt-get install curl sudo docker run --name magellan-nbi -d -p 80:8080 obrienlabs/magellan-nbi:0.0.3-ia64 curl http://127.0.0.1/nbi/api {"id":7,"content":"PASS remoteAddr: 172.17.0.1 localAddr: 172.17.0.2 remoteHost: 172.17.0.1 serverName: 127.0.0.1"}
Running Docker in AWS
Running Docker in Azure
Docker Installation
see Kubernetes Developer Guide#DockerInstallation
Docker Login
docker login -u user -p token
Docker Run
docker run -p 8080:8080 -p 8001:8001 -d --name drools-workbench jboss/drools-workbench-showcase:latest docker run -p 8180:8080 -d --name kie-server --link drools-workbench:kie-wb jboss/kie-server-showcase:latest
Docker Pull
Check your login first
obrienlabs:devops michaelobrien$ docker login Authenticating with existing credentials... Login Succeeded
Docker Exec
Docker History
Docker log
docker logs -f testconfig_aai-resources.api.simpledemo.openecomp.org_1 |
---|
Docker Build
add --rm=true to remove images tagged with <none>
from https://github.com/obrienlabs/eventstream/commit/a4175039f6aa16d72d17e827e8d98470369b7af0
# variables CONTAINER_IMAGE=eventstream PORT_IN=8080 PORT_OUT=8888 RELEASE_ID=0.0.1 DOCKERFILE=DockerFile # static templates BUILD_ID=10001 BUILD_DIR=builds mkdir ../../$BUILD_DIR TARGET_DIR=../../$BUILD_DIR/$BUILD_ID mkdir $TARGET_DIR cd ../../ #mvn clean install -U -DskipTests=true cd src/docker cp ../../target/*.jar $TARGET_DIR cp $DOCKERFILE $TARGET_DIR cp startService.sh $TARGET_DIR cd $TARGET_DIR docker build --rm=true --no-cache --build-arg build-id=$BUILD_ID -t obrienlabs/$CONTAINER_IMAGE -f $DOCKERFILE . #docker tag $CONTAINER_IMAGE:latest $CONTAINER_IMAGE:latest docker tag obrienlabs/$CONTAINER_IMAGE obrienlabs/$CONTAINER_IMAGE:$RELEASE_ID docker tag obrienlabs/$CONTAINER_IMAGE obrienlabs/$CONTAINER_IMAGE:latest # dockerhub docker push obrienlabs/$CONTAINER_IMAGE:$RELEASE_ID docker push obrienlabs/$CONTAINER_IMAGE:latest # locally docker stop $CONTAINER_IMAGE docker rm $CONTAINER_IMAGE echo "starting: $CONTAINER_IMAGE" docker run --name $CONTAINER_IMAGE \ -d -p $PORT_OUT:$PORT_IN \ -e os.environment.configuration.dir=/ \ -e os.environment.ecosystem=sbx \ obrienlabs/$CONTAINER_IMAGE:$RELEASE_ID
Docker Registry Image Search
where the image name is "dcae-controller" obrienbiometrics:pgaas michaelobrien$ curl -Ss -u docker:docker https://nexus3.onap.org:10001/v2/dcae-controller/tags/list | jq { "name": "dcae-controller", "tags": [ "0.1.0-SNAPSHOT", "1.0.0" ]} |
---|
Docker Push
Dockerhub
root@obriensystemskub0:~/oom/kubernetes/dcae/pgaas# export DOCKER_ID_USER="obrienlabs" root@obriensystemskub0:~/oom/kubernetes/dcae/pgaas# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: obrienlabs Password: Login Succeeded root@obriensystemskub0:~/oom/kubernetes/dcae/pgaas# docker build -t obrienlabs/pgaas -f Dockerfile . Sending build context to Docker daemon 23.55 kB Step 1 : FROM ubuntu:16.04 ---> d355ed3537e9 .... Successfully built 257430a38254 root@obriensystemskub0:~/oom/kubernetes/dcae/pgaas# docker tag obrienlabs/pgaas obrienlabs/pgaas:1 root@obriensystemskub0:~/oom/kubernetes/dcae/pgaas# docker push obrienlabs/pgaas:1 The push refers to a repository [docker.io/obrienlabs/pgaas] ee716c896001: Pushed ....5a4c2c9a24fc: Pushed cb11ba605400: Pushed 1: digest: sha256:fb09855b323fe83aaa161725910cd2f6d7ff6306035e6f5f2df40b99149e8fed size: 6157 pull on separate machine obrienbiometrics:oom michaelobrien$ docker pull obrienlabs/pgaas:1 1: Pulling from obrienlabs/pgaas 23a6960fe4a9: Extracting [===> ] 3.441MB/45.89MB e9e104b0e69d: Download complete cd33d2ea7970: Download complete 534ff7b7d120: Download complete |
---|
Docker save/load
Docker cleanup
Docker full system prune
$ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 41 13 9.123GB 4.001GB (43%) Containers 24 22 4.823GB 4.823GB (99%) Local Volumes 8 1 8.316GB 2.904GB (34%) Build Cache 0 0 0B 0B $ docker system prune -a WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all images without at least one container associated to them - all build cache Total reclaimed space: 13.19GB $ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 11 11 757.9MB 48.46MB (6%) Containers 22 22 6.017kB 0B (0%) Local Volumes 8 0 8.316GB 8.316GB (100%) Build Cache 0 0 0B 0B
Stop all containers
docker stop $(docker ps -a -q)
Remove all containers
docker rm $(docker ps -a -f status=exited -q)
Remove all images
docker rmi $(docker images -a -q) --force
Remove all volumes
docker volume rm $(docker volume ls)
Updating WARs/JARs
Attaching to a Debug Port
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432
List Docker Mounts
Docker fails to start on OSX
https://github.com/docker/for-mac/issues/989
reset to defaults
Docker Fails to start on Windows running WSL2
If you see "Hardware assisted virtualization and data execution protection must be enabled in the BIOS" - enable hyperv in addition to wsl2, check VTx and virtualization=true in task manager/cpu, reboot
https://docs.docker.com/desktop/windows/troubleshoot/
https://github.com/docker/for-win/issues/6689
Install and enable hyper-v if not already enabled (even though we are using WSL2)
PS C:\Windows\system32> dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All Deployment Image Servicing and Management tool Version: 10.0.19041.844 Image Version: 10.0.19043.1165 Enabling feature(s) [==========================100.0%==========================] The operation completed successfully. PS C:\Windows\system32> bcdedit /set hypervisorlaunchtype auto The operation completed successfully.
Docker in Docker
DIND
http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/
https://github.com/jpetazzo/dind
https://hub.docker.com/_/docker/
Run an Ubuntu Desktop container on Docker - for nested Docker
We used this one in ONAP https://hub.docker.com/r/dorowu/ubuntu-desktop-lxde-vnc - it needs a volume - so we will likely need do dockerfile it - to save state - if you dont
have local drive share capability from Docker Desktop. Goto http://127.0.0.1:6080/
docker run -p 6080:80 -d --name ubuntu dorowu/ubuntu-desktop-lxde-vnc # test a file copy docker cp pom.xml ubuntu:/root/pom.xml # check it docker exec -it ubuntu bash root@6950d3be0f24:/root# ls Desktop pom.xml
Network Connections to Other Docker Containers on the same Host
localhost won't work inside a container - it just resolves to itself - use a network or the following URLs
in mac
docker.for.mac.localhost
in windows or both
host.docker.internal
Docker Images by Language
Java
Alpine
Tomcat
Swift
Python
Docker-compose - legacy single node minimal orchestration
Don't use docker-compose over Kubernetes for various reasons including the fact it is a minimal deprecated single-node orchstrator
But if you absolutely need it
root@k8s:~# curl -L "https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose root@k8s:~# chmod +x /usr/local/bin/docker-compose root@k8s:~# docker-compose --version docker-compose version 1.28.4, build cabd5cfbroot@k8s:~/docker-compose# docker-compose up Creating docker-compose_backend_1 ... done backend_1 | Hello from Docker! root@k8s:~/docker-compose# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 19a4758a1ea7 hello-world "/hello" 13 seconds ago Exited (0) 11 seconds ago
Links
https://github.com/moby/moby/issues/22910
https://betterprogramming.pub/docker-tips-clean-up-your-local-machine-35f370a01a78
1 Comment
Michael O'Brien
My docker registry https://wiki.onap.org/display/DW/TSC+2018-12-20