Skip to content

Instantly share code, notes, and snippets.

@aeinbu
Last active July 5, 2024 14:07
Show Gist options
  • Save aeinbu/41f66c99db4b5a7666fdb1d285ddb973 to your computer and use it in GitHub Desktop.
Save aeinbu/41f66c99db4b5a7666fdb1d285ddb973 to your computer and use it in GitHub Desktop.
docker cheat sheet

Running docker images cheatsheet

Download a docker image

Download the image called debian:

docker pull debian

Create a container (and start it)

The container in the samples will be named "debby"

docker run -dit -v /Users/arjan/dev:/host --name debby debian:latest /bin/bash
  • -dit flags - These just work, dont ask ;)
    • d for detached
    • i for interactive
    • t for virtual tty
  • -v /Users/arjan/dev:/host mounts a volume to the container. The first argument represents the source from the host, the second argument (after the :) says where to mount it in the container. Here /host is the folder inside the docker container that points to /Users/arjan/dev on the host machine.
  • --name debby gives the container a name. This name is used when managing the container. (See below)
  • debian:latest is the name and version (or tag) of the image to create a container from
  • /bin/bash is the program to run in this container A docker container will run only for as long as it has a running process. When that process stops, the container will terminate too. Therefore we start this container with /bin/bash, since that won't stop by itself.

Other flags:

  • -p 8080:80 will set up your host's port 8080 to point to port 80 inside the container. The first argument represents the port on the host, the second argument (after the :) is the port in the container.
  • -e to set environment variables. (Like -e "MY_ENVIRONMENT_VAR=some-value".)
  • --rm will remove the container immediatly after it stops

Starting, stopping (and generally managing the container)

"debby" is the name of the container, given when the container was created.

docker container ls -a
docker container start debby
docker container attach debby
docker container stop debby
docker container rm debby

Some premade containers for testing different servers on my M1 Mac

Metamory.Server

docker pull aeinbu/metamory:latest

To use this Metamory.Server from you host machine, you must at least setup forwarding of port 5000 (for http) or 5001 (for https) and some environment variables. Minimum setup:

docker run -dit -p 5000:5000 -v -e NoAuth=true -e ASPNETCORE_HTTP_PORTS=5000 aeinbu/metamory

You should give the container a name, and set up where to store the data. This Metamory.Server container will store its data to the folder ~/metamory.

docker run -d -v ~/metamory:/data -p 5000:5000 --name my-metamory-server aeinbu/metamory

See https://hub.docker.com/repository/docker/aeinbu/metamory/ and https://github.com/aeinbu/Metamory.Server for more options and information

Postgres or PostgreSQL

docker pull postgres:latest

To use this Postgres server from you host machine, you must at least setup forwarding of port 5432 and some environment variables. Minimum setup:

docker run -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

You should give the container a name, and set up where to store the data. This PostgreSQL container will store its data to the folder ~/postgres.

docker run -e POSTGRES_PASSWORD=mysecretpassword -v ~/postgres:/var/lib/postgresql/data -p 5432:5432 -d --name my-postgres postgres

See https://hub.docker.com/_/postgres and https://github.com/docker-library/docs/blob/master/postgres/README.md for more options and information

Mongo DB

docker pull mongo

To use this Mongo DB from you host machine, you must at least setup forwarding of port 27017. Minimum setup:

docker run -dit -p 27017:27017 mongo

You should give the container a name, and set up where to store the data. This Mongo container will store its data and configuration to the folders ~/mongo/db and ~/mongo/configdb

Setup a container with a specified name and volumes mapped to folders of my choice:

docker run -dit -v ~/mongo/db/:/data/db -v ~/mongo/configdb/:/data/configdb -p 27017:27017 --name my-mongo mongo

Both above samples will run starting mongod (the Mongo deamon), so the container should stay running and you can connect to it on 127.0.0.1:27017.

See https://hub.docker.com/_/mongo for more options and information.

MS SQL Server

docker pull mcr.microsoft.com/azure-sql-edge

To use this Microsoft SQL Server from you host machine, you must at least setup forwarding of port 1433 and some environment variables. Minimum setup:

docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=Pa$$w0rd" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 -d mcr.microsoft.com/azure-sql-edge

You should give the container a name, and set up where to store the data. This Microsoft SQL Server image will store its data to the volumes /var/opt/mssql-extensibility, /var/opt/mssql-extensibility/data and /var/opt/mssql-extensibility/log.

docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=P@ssw0rd123" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -v ~/ms-sql-server/dot:/var/opt/mssql-extensibility -v ~/ms-sql-server/data:/var/opt/mssql-extensibility/data -v ~/ms-sql-server/log:/var/opt/mssql-extensibility/log -p 1433:1433 -d --name=my-ms-sql-server mcr.microsoft.com/azure-sql-edge

See https://hub.docker.com/_/microsoft-azure-sql-edge for more options and information.

Seq

docker pull datalust/seq:latest

To use this Seq server from you host machine, you must at least setup forwarding of port 80 for the combined UI and ingest and some environment variables. Minimum setup:

docker run -e ACCEPT_EULA=Y -p 5341:80 --restart unless-stopped -d datalust/seq:latest

You should give the container a name, set up seperate UI and ingestion endpoints, and set up where to store the log data. This Seq Server image will store its data to the folder ~/seq.

docker run -e ACCEPT_EULA=Y -e SEQ_FIRSTRUN_ADMINPASSWORDHASH=mysecretpassword -d -v ~/seq:/data -p 80:80 -p 5341:5341 --restart unless-stopped --name seq datalust/seq

See https://hub.docker.com/r/datalust/seq and https://datalust.co/seq for more options and information

Grafana

docker pull grafana/grafana-oss:latest

To use this Grafana server from you host machine, you must at least setup forwarding of port 3000 for the UI. Minimum setup:

docker run -d -p 3000:3000 grafana/grafana-oss

You should give the container a name, and set up where to store the data. This Grafana server image will store its data and configuration to the folder ~/grafana.

docker run -d -v ~/grafana/:/var/lib/grafana -p 3000:3000 --name=grafana grafana/grafana-oss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment