cf

Docker Commands

docker run

docker run
  -d (run detached)
  -it (interactive terminal)
  -p (publish a port)
  -v (mount a volume)
  --name (name a container)
  --link (communicate between containers)
  --rm (auto-delete when container stops)
  -e NAME=value (environment variables)

docker exec

docker exec  # Run a command inside a container

docker ps

docker ps  # See what container are running

docker logs

docker logs  # View log output from a container

Clean up

docker rm -f container-name
docker image rm image-name
docker volume rm volume-name
docker
> information
> version
> images

Managing docker images

docker system prune --force
docker system df

docker 
docker rm $(docker ps -a -q -f "status=exited")
docker images --filter "dangling=true" -q --no-trunc

#docker rmi $(docker images --filter "dangling=true" -q --no-trunc) -f

docker images --filter=reference='asinfxacr.azurecr.io/tcbuildagents-test/*:*' -aq

docker rmi $(docker images --filter=reference='asinfxacr.azurecr.io/tcbuildagents-test/*:*' -aq) -f

docker images --filter "dangling=true" -q --no-trunc | measure-object

docker rmi $(docker images --filter "dangling=true" -q --no-trunc) -f

# This may work ...  docker rmi $(docker images -q)

With TeamCity

Used to monitor and / or stop [TeamCity] Agents via:

docker --host tcp://10.81.4.233:2375 ps
docker --host tcp://10.81.4.233:2375 info
...
docker -H tcp://10.81.4.233:2375 stop unruffled_spence
docker -H tcp://10.81.4.233:2375 rm unruffled_spence

docker -H tcp://10.81.4.201:2375 pull asinfxacr.azurecr.io/tcbuildagents-test/asset_dotnetcore

# 
docker -H tcp://10.81.4.233:237 pull asinfxacr.azurecr.io/tcbuildagents-test/promotion:0.0.21
docker -H tcp://10.81.4.233:2375 logs 

docker image list

# In a folder with a DockerFile

docker build --memory 10Gb --tag my.tag.name.01 . # The trailing period is necessary

Pulling images for Azure ACR

az login # Bounce to browser
az acr login --name asinfxacr
docker pull asinfxacr.azurecr.io/tcbuildagents-test/promotion:0.0.18

Environment Variables

$ env | grep DOCKER
$ eval "$(docker-machine env dev)"
$ env | grep DOCKER
DOCKER_HOST=tcp://192.168.99.101:2376
DOCKER_CERT_PATH=/Users/nathanleclaire/.docker/machines/.client
DOCKER_TLS_VERIFY=1
DOCKER_MACHINE_NAME=dev
$ # If you run a docker command, now it runs against that host.
$ eval "$(docker-machine env -u)"
$ env | grep DOCKER
$ # The environment variables have been unset.

Docker and its use in a Mobile CI environment:

Docker is stateless, so where do we store our state? And indeed what is the state.

Need a Mobile CI (mCI) workflow for code & testing which outlines all the O/P’s and whatever state is needed. Only have one build -> xxx.apk, but we have many test environments.

Jenkins & Docker

Android & Docker


  • Alpine Linus docker run gliderlabs/alpine (Includes busybox & /usr/bin/vi)
  • Python at Microsoft - https://blogs.msdn.microsoft.com/pythonengineering/2016/02/12/welcome/
  • Python / Docker - http://blog.deepgram.com/import-a-docker-container-in-python/
  • Tao Of Mac - http://taoofmac.com/space/HomePage interesting blog on both Python & Docker

Multi-stage Dockerfiles

Example docker file to build dotnet application abd package just the application (From the build enviroment).

FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app

# Copy csproj and retor as distinct layers
# This is done separatly as the nuget repos are less likely to change
COPY *.csproj ./
RUN dotnet restore

# Copy everthing else
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "mySampleApp.dll"]

boot2docker

Located here - /usr/local/share/boot2docker

docker-machine

is the OS-X VM used to run Docker. A nice command would be docker-machine inspect default or docker-machine start. The default machine is called default.

If the network has broken things (as mine often does) then a quick docker-machine restart & docker-machine env / eval $(docker-machine env) may help.

Read the docs for more details.

A very simple example:

git clone https://github.com/cloudnativedevops/demo.git
cd demo
code .
docker version
docker container run -p 9999:8888 --name hello cloudnatived/demo:hello

And then..

docker image build -t myhello .
docker container run -p 9999:8888 myhello   # open http://localhost:9999/
docker login
# ... authenticate if necessary
docker image tag myhello rikwatson/myhello
ddocker image push rikwatson/myhello
ddocker container run -p 9999:8888 rikwatson/myhello

docker rmi $(docker images --filter=reference='asinfxacr.azurecr.io/tcbuildagents-test/*:*' -aq) -f

ebf4bee9
Deleted: sha256:75f80b4721bc13a9db6b4b5ef2e52294a2e739d2fbd135c95c7f290961245287
Deleted: sha256:cd769883bec15f6b57ec841159fe4ff9c029f862a2c2b7046d3084babda9f416
Deleted: sha256:9212693dc170fd8d2bf595a11663c2de7910a77d8ff75c5e0e72ede3a24d174b
Deleted: sha256:d9993d4728e9150cab7a2e8ea84615f7930002f97dd7b6f90dcc5b8cde36c866
Deleted: sha256:0eb5f6c9e92b4a05dcdaf6b50c5882fe20ca4746f382a2f3e0072cbdc2729179
Deleted: sha256:c389f1861e1a72cb60b42352dcb1a8a84e39922c6e71edf1254ff4bb11c61cfd
Deleted: sha256:a28dc71e749c3ecba262529d518315d76f4aa53996d7f35d0051ce2ddd7ebd32
Deleted: sha256:ac7c1266a4cef9bbe2275972b0030ea6c49cf213d7ce50191dd2f8b608571a36
Deleted: sha256:8bc6c8dac4d038eacdb10ceecab3ce1d56c53bc3e2b400de08eb7e4373d4e0c1
Deleted: sha256:4c5102c2e20215e8a87fbe71b3732c6d5e003cb75796bccab2cd9c45aac5243b
Deleted: sha256:f2a8c5b2f71a8daf7be73f4d01f28f20db9e9cc4ed3c0ceabe9be8f2362c2656
Deleted: sha256:86daa7301ace4c6ce72a8e06306ac2871943b75da4bb31846d0ce8eee6e8437c
Deleted: sha256:fec56c780c4822e4df489377197aa3f32c30a5c426e3c61c18d728b4a0ff8f62
Deleted: sha256:5d0a43bac7d6da07c2b71b9e5c0d5a8603c93fc25889b216192e2bdb0faa9559
Deleted: sha256:d52dc441370093dfc16bb112acd8c45a5623c0324ec63ecdbdc0300899170c12
Deleted: sha256:0166be5e24910cf1ef94808499b13b74e7293d17a93922d4d2644ebb8e37b3a2
Deleted: sha256:98d00bd3a39445c6d509dcb9cd739db5af556d599b1565afd07f4d14170bc8b7
Deleted: sha256:9da2edbb03d6b922c22c46f48869bfc237fdf8524ea462004653e3445e2550d0
Deleted: sha256:2713de6a73d3c641d9e1e570b26f26018ead0a1e2e724c77de29323ac09fc3da
Deleted: sha256:d463ba2100937556297f1b2a24e34c430c5aabdb9038b086a88e5d7fb558659f
Deleted: sha256:1fa25760c63b371f55d8c92cf3df59c20e93b35b825ca0b08997789e5977b563
Deleted: sha256:fad748ddbf129411896100969ff7ef3b30c69cf79d62f88d0932354884a99901
Untagged: asinfxacr.azurecr.io/tcbuildagents-test/product_dotnetcore:0.0.64
Untagged: asinfxacr.azurecr.io/tcbuildagents-test/product_dotnetcore@sha256:35eafd77e82849dcbaf57389b6a29706a8ca2962fd860b6cea90db564f12fb81
Untagged: asinfxacr.azurecr.io/tcbuildagents/product_dotnetcore:0.0.64
Untagged: asinfxacr.azurecr.io/tcbuildagents/product_dotnetcore@sha256:35eafd77e82849dcbaf57389b6a29706a8ca2962fd860b6cea90db564f12fb81
Deleted: sha256:61fb649a2ea00c299d9a69cef13024377cbaed44ee8e1ce31078b2f5d259bd60
Deleted: sha256:1ea76a2eaa8b40f6f3dc36e8b9684843a9d47601fcb8dcf0027bfbe38dc5c480
Deleted: sha256:828660b5268482252a04db68f61579e6d15d6502ddb265eb8141b979c409937b
Deleted: sha256:854e5704bcd920b50a9d49502067099a99931fa2a0c09f6cc32e71625344e5ed
Deleted: sha256:9e6e415ad5bdef83c9c3b98a4a56065fdea95dda9a05ab918c0a9fcc46db710c
Deleted: sha256:aa7c8d29040a0c78599694ffe7cefcfc493cfaa92e757a3e8f2b291ffdc629f6
Deleted: sha256:2e60d7cd96c832436ff1f18324e0eccc9ee42a7df1bd3d7e6fc7c1556f86e551
Deleted: sha256:bf4fed5e9845f859e5fb4c89dec67b8b4ff95856633fc1d38d430ba1f1f1c56a
Deleted: sha256:b46dcc85f7b66d4a51633ab0b15e11a98d8983416d819b20f60867f97dc8cf86
Untagged: asinfxacr.azurecr.io/tcbuildagents-test/product_dotnetcore:0.0.65
Untagged: asinfxacr.azurecr.io/tcbuildagents-test/product_dotnetcore@sha256:639211c0c767e8c8a375efd3091007e5a47bd2ed12b1b5578c2f09da07304e54
Untagged: asinfxacr.azurecr.io/tcbuildagents/product_dotnetcore:0.0.65
Untagged: asinfxacr.azurecr.io/tcbuildagents/product_dotnetcore@sha256:639211c0c767e8c8a375efd3091007e5a47bd2ed12b1b5578c2f09da07304e54
Deleted: sha256:6b7c465b4e7d747786d60edb09daeac55b2721210dc711f3c7af3f1b08a5a3da
Deleted: sha256:7a59b40db55cec513ac430383cab2fd8b05a76c741fe620bff2df38bb23fa69f
Deleted: sha256:6d2ce7878a43086915ebc9f8b0a6abfeae48641f486b2cac6b73ab194552858b
Deleted: sha256:911405e88199e334d06598cb6c89551cde05afe36ad8267eda9453a4a66ea216
Deleted: sha256:a5f67ed5654e6bf062843e14e0ba42a2370b9957490ff205b8d0cbef14d1a130
Deleted: sha256:4467689f3932a42d1d0acf629ba88679e766909c5562d8a8e54f73976344c69f
Deleted: sha256:d5d191e699df570e3fac91f29408508d7140fdedcda0adb97264e172ae029649
Deleted: sha256:6f1ddb68379cd030ee1af1b8511ff6beef9b5d03d4a2518f3776c7960fd8c0f7
Deleted: sha256:33a91107d57c3fec6ecae6d4e46049cf9eeaa8215322d1a6d045a31d8e76c4d5
docker : Error: No such image: 50ce855d4b07
At C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.2\Downloads\script41.ps1:1 char:1
+ docker rmi $(docker images --filter=reference='asinfxacr.azurecr.io/t ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: No such image: 50ce855d4b07:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Error: No such image: 2b4a4013eb96
Error: No such image: 982fe3132fe1
Error: No such image: 0d02be6f1374
Error: No such image: 672c0e4d7170
Error: No such image: e9b6398046eb
Error: No such image: bec1e9629733


layout: post title: “Docker” permalink: /docker categories: docker mobile ci jenkins devops —

Docker

And its use in a Mobile CI environment:

Docker is stateless, so where do we store our state? And indeed what is the state.

Need a Mobile CI (mCI) workflow for code & testing which outlines all the O/P’s and whatever state is needed. Only have one build -> xxx.apk, but we have many test environments.

Jenkins & Docker

Android & Docker


Alpine Linus docker run gliderlabs/alpine (Includes busybox & /usr/bin/vi)

Python at Microsoft - https://blogs.msdn.microsoft.com/pythonengineering/2016/02/12/welcome/

Python / Docker - http://blog.deepgram.com/import-a-docker-container-in-python/

Tao Of Mac - http://taoofmac.com/space/HomePage interesting blog on both Python & Docker


boot2docker

Located here - /usr/local/share/boot2docker

docker-machine

is the OS-X VM used to run Docker. A nice command would be docker-machine inspect default or docker-machine start. The default machine is called default.

If the network has broken things (as mine often does) then a quick docker-machine restart & docker-machine env / eval $(docker-machine env) may help.

Read the docs for more details.

docker run gliderlabs/alpine echo Hello Rik

Run 'Docket Qucikstart Terminal', then `eval $(docker-machine env)`

docker-machine start
docker-machine inspect default
docker-machine restart

docker images
docker run rikwatson/docker-whale
docker run cellofellow/ffmpeg
docker ps
docker run hello-world
docker run -it ubuntu bash
service docker[.io] status

A very simple example:

git clone https://github.com/cloudnativedevops/demo.git
cd demo
code .
docker version
docker container run -p 9999:8888 --name hello cloudnatived/demo:hello

And then..

docker image build -t myhello .
docker container run -p 9999:8888 myhello   # open http://localhost:9999/
docker login
# ... authenticate if necessary
docker image tag myhello rikwatson/myhello
ddocker image push rikwatson/myhello
ddocker container run -p 9999:8888 rikwatson/myhello

Using Kubernetis instead:

kubectl run demo --image=rikwatson/myhello --port=9999 --labels app=demo
kubectl port-forward deploy/demo 9999:8888