Docker usefull commands

Docker Desktop is an easy-to-install application for your Mac or Windows environment that enables you to build and share containerized applications and microservices. Docker Desktop includes Docker Engine, Docker CLI client, Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper.

Well, I’ve using docker for a while but not in my daily drive, so I have a problem. I always need to search for the same commands all the time. So that’s why this post was created for

How to install

Download, drag and drop, and run. Docker installation has changed over time, nowadays the process is now more guided.

Basic commands to get started.

Disclaimer: These commands were obtained from the docker Getting Started

Clone the repo and enter

> docker run --name repo alpine/git clone
> docker cp repo:/git/getting-started/ .

Build the docker image and run it

docker build -t docker101tutorial . 
docker run -d -p 80:80 --name docker-tutorial docker101tutorial

Share that image with anybody else

docker tag docker101tutorial whistler092/docker101tutorial 
docker push whistler092/docker101tutorial

There are several commands here:

  • docker ps allows you to see the running containers.
  • docker ps -a allows you to see all the containers.
  • docker start allows you to start a container.
  • docker stop allows you to stop a container.
  • docker rm allows you to remove a container.
  • docker rmi allows you to remove an image.
  • docker images allows you to see all the images.
  • docker image rm allows you to remove an image. That image cannot be used anymore.

Another command to get started.

  • docker build -t myuser/myimage . Build an image based on the Dockerfile in the current directory. Tag is as myuser/myimage.
  • docker run [image id or image tag] Create and start a container based on the provided image id or tag.
  • docker run -it [image id or image tag] Create and start a container, but that flags also overrides the default command.
  • docker ps Print out information about all the running containers.
  • docker ps -a Print out information about all the containers.
  • docker exec -it [container id] [cmd command] Execute the given command in a running container
  • docker logs [container id] Print out the logs of a container.

Run postgresql

> docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=your_secret_password -d postgres 

Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
eff15d958d66: Pull complete
de2b4ab3ade5: Pull complete
108afa831d95: Pull complete
e5821d5963ce: Pull complete
5be06220aa99: Pull complete
c877668f09b8: Pull complete
7037ade1772d: Pull complete
d46bc4e17ddc: Pull complete
a60906bcf87f: Pull complete
a1c85f71c941: Pull complete
69f50e484cab: Pull complete
2f8a286a55a4: Pull complete
8d590b0d720c: Pull complete
Digest: sha256:1fe27b334443793af98d7eb320ad6f9f30fcc9bc068f545cb46ec01cefe9c8ee
Status: Downloaded newer image for postgres:latest

>  docker ps
ad8e89cebc59   postgres            "docker-entrypoint.s…"   21 seconds ago   Up 21 seconds>5432/tcp   postgresql-container

to stop it and run it:

> docker ps 
ad8e89cebc59   postgres   ...

> docker stop ad8e89cebc59

> docker ps

>  ⇒  docker ps -a
CONTAINER ID   IMAGE               COMMAND                  CREATED       STATUS                          PORTS     NAMES
ad8e89cebc59   postgres            "docker-entrypoint.s…"   3 hours ago   Exited (0) About a minute ago             postgresql-container

> docker start postgresql-container

Now you can connect into your postgresql database

Run MSSQL Server

docker pull microsoft/mssql-server-linux:2017-latest 

docker run -d --name macsqlserver -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=your_secret_password' -e 'MSSQL_PID=Developer' -p 1433:1433 microsoft/mssql-server-linux:2017-latest | How I setup a Raspberry Pi 3 Cluster Using The New Docker Swarm Mode In 29 Minutes | by Malcolm Jones | Medium | About Windows containers | Microsoft Docs | Building a Bank with Kubernetes | SkillsCast | 19th October 2016 | Are Docker Containers Good for Your Database? - Percona Database Performance Blog

Nginx with reverse proxy | Host multiple websites on a single host with Docker | nginx-proxy/nginx-proxy: Automated nginx proxy for Docker containers using docker-gen | ehazlett/interlock: Docker Event Driven Plugin System | Automated Nginx Reverse Proxy for Docker · | Playing with Docker and nginx : from multi-domain to multi-container | Yann Moisan

Containerizing apps | What are containers and how to containerizing an Asp.Net MVC application using Docker | by Somak Das | Medium | Dockerize an existing ASP.NET MVC 5 application | dotnetthoughts | Back to the Future: Containerize Legacy Applications - YouTube