Docker My Go Tutorial

Docker diff command

Inspect changes to files or directories on a container’s filesystem


List the changed files and directories in a container᾿s filesystem since the container was created. Three different types of change are tracked:

docker diff CONTAINER

Extended description

AA file or directory was added
DA file or directory was deleted
CA file or directory was changed

docker run –name version-a busybox:latest touch /HelloWorld

docker diff version-a

A /HelloWorld

Different comparison check of the current version of Docker version-a against Docker busybox.

Docker Window WSL2

Docker Desktop (2.3.x) Windows WSL 2


Creating Docker Volumes

the volume create command of the docker

docker volume create testVolume

This command creates a data volume name testVolume that can be used by a specific container or shared among a cluster of containers.

docker volume inspect testVolume

The resultant data shows that our testVolume is mounted at the location /var/lib/docker/volumes/testVolume/_data of our host machine.

sudo ls -al /var/lib/docker/volumes/redis-data/_data

-rw-r--r-- 1 systemd-coredump username 92 Jun  1 18:57 dump.rdb

Dockerfile Best Practices

Best practices for writing Dockerfiles

FROM alpine3.12
COPY . /app
RUN make /app
CMD main

Each instruction creates one layer:

  • FROM creates a layer from the alpine 3.12 Docker image.
  • COPY adds files from your Docker client’s current directory.
  • RUN builds your application with make.
  • CMD specifies what command to run within the container.


Docker Compose

Docker My Go Tutorial

Build a binary program on and executed it in Docker. DockerFile: alpine + golang

FROM golang:1.14-alpine AS build

We are creating our image using the base image golang:alpine. This is basically an image just like what we want to create and is available for us on a Docker repository. This image runs the alpine Linux distribution which is small in size and has Golang already installed which is perfect for our use case. 

From golang:alpine

RUN mkdir /files
COPY hello.go /files
WORKDIR /files

RUN go build -o /files/hello hello.go
ENTRYPOINT [ "/files/hello" ]

create a folder in docker and copy the golang source file to the created folder. Choose the created folder as our WORKDIR. Define Docker RUN to build a binary with go tool (build -o) to use the source file and specify the output. Docker ENTRYPOINT to run the binary file after Docker image has been loaded.

docker build -t go_hello:v1 .

Docker ‘build’ command with ‘-t’ options tag a new name for image and version. Docker ‘images’ command will list show an image name if above docker command has not error of build a new image file.

docker run –rm go_hello:v1

Docker ‘run’ command load the go_hello:v1 into a container and execute the the ENTRYPOINT defined in the Dockerfile.

docker tag go_hello:v1 "shankuo/go_hello:v1"
docker push "shankuo/go_hello:v1"

Docker ‘push’ command delivery the copy of docker image to the Docker Hub.