Skip to content

Docker

Open your favorite Terminal and run these commands. Installing docker on Mac with Homebrew Cask:

sh
brew install docker --cask

Get docker version:

sh
docker --version

If the above command doesn’t return the Docker version, you may need to start the Docker daemon first. You can do that by searching for Docker in Spotlight or in the Application folder in Finder and running it. Get docker info:

sh
docker info

Create a docker image: Before creating a docker image, make sure to add a Dockerfile in the current directory

sh
docker build -t golang-docker .

Run a docker image:

sh
docker run -d -p 80:80 golang-docker

List all images docker images:

sh
docker images

Check the running processes:

sh
docker ps

Stop a running process:

sh
docker stop 35a3173485aa

Login in docker hub:

sh
docker login

Tag an image to make it ready for pushing to docker hub:

sh
docker tag golang-docker mnkrana/golang-docker:latest

Push tagged image to docker hub:

sh
docker push mnkrana/golang-docker

Login in github docker packages: First, export your personal access token from developer setting in github. Then, export it like this

sh
export PAT=<your PAT>

Now, to login

sh
echo $PAT | docker login ghcr.io --username phanatic --password-stdin

Push to github packages: Make sure to tag your image with ghcr.io like this

sh
docker tag golang-docker ghcr.io/mnkrana/golang-docker

Now, push it to github packages:

sh
docker push ghcr.io/mnkrana/golang-docker2:latest

Remove docker image:

sh
docker image rm -f mnkrana/golang-docker

Show all containers:

sh
docker ps -a

Delete all containers:

sh
docker rm -f $(docker ps -a -q)

Prune docker system:

sh
docker system prune -a

Check logs

sh
docker run --name test -d -p 80:80 golang-docker
docker logs -f test

Inspect running container

sh
docker inspect <container-name>