Skip to content

Instantly share code, notes, and snippets.

@altherlex
Last active June 18, 2022 07:28
Show Gist options
  • Save altherlex/0bd3f6d214cda0436613d3a4985fa3a9 to your computer and use it in GitHub Desktop.
Save altherlex/0bd3f6d214cda0436613d3a4985fa3a9 to your computer and use it in GitHub Desktop.
Docker main commands
# list of all images on your system
$ docker images

# run a command on image busybox
$ docker run busybox echo "hello from busybox"

# shows containers that are currently running
docker ps 

# shows containers that were ran
docker ps -a

# inside the container
$ docker run -it busybox sh
$ docker run -d -p 5000:5000 --name $containerName $imageName
$ docker run --name src -p 8081:8081 -d test -e MYSQL_PASSWORD=12345678 -e MYSQL_DATABASE=testdb -e MYSQL_USER=root -e MYSQL_HOST=192.168.0.1
$ docker run -ti --entrypoint /bin/bash myhi

# Using databse config host: host.docker.internal
$ docker run -p 3000:8000 -v /tmp/mysql.sock:/tmp/mysql.sock myhi

# Get Container's IP address
$ docker inspect 31a50b31c8fb | grep IPAddress
$ docker inspect --format '{{.NetworkSettings.IPAddress}}' 31a50b31c8fb
$ docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'  875bed5f8c1c

# Container port available
$ docker port 31a50b31c8fb

# [For a Mac's] Tie Gemfile.lock to the Linux versions of libraries
$ docker run --rm -v "$(pwd)":/usr/src/app -w /usr/src/app ruby:2.1.5 bundle install

--

Remove

# Remove container
$ docker rm 305297d7a235

# Remove all containers
$ docker container prune

# Delete image
$ docker image rm 4c46ae5cf5ea

# Purging all unused containers, volumes, and networks
$ docker system prune

# Remove stopped containers
$ docker system prune -a

Docker-compose

$ docker-compose exec mariadb-service-name /bin/bash
$ docker-compose up -d --build
$ docker-compose up -d --force-recreate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment