Last active
June 11, 2022 12:50
-
-
Save matthewblott/6799d6c92bee4d92680094023536027d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# See ... | |
# https://www.tutorialspoint.com/docker | |
# https://docs.docker.com/engine/reference/commandline/docker/ | |
# ==== | |
# Hubs | |
# ==== | |
# hub = host registry of images (where the images are downloaded from) | |
# ======== | |
# Networks | |
# ======== | |
# create network | |
docker network create --driver=bridge --gateway=192.168.0.1 --subnet=192.168.0.0/16 main | |
# connect a container to an existing network | |
docker run --name container_name --network=main | |
# ====== | |
# Images | |
# ====== | |
# list images | |
docker images | |
# list image ids only | |
docker images -q | |
# download image | |
docker pull image_name | |
# remove image | |
docker rmi image_id | |
# create instance of container from an image | |
docker run image_name | |
# create instance of container from an image in interactive mode | |
docker run container_name -it /bin/bash | |
# ========== | |
# Containers | |
# ========== | |
# list containers running | |
docker ps | |
# list all containers | |
docker ps -a | |
# create container | |
docker create --name container_name image_name | |
# rename | |
docker rename container_name new_container_name | |
# start container | |
docker start container_id | |
# stop container | |
docker stop container_id | |
# delete container | |
docker rm container_id | |
# kill container's running processes | |
docker kill container_id | |
# inspect container | |
docker inspect container_id | |
# copy and start new container and change port | |
docker commit container_name new_image_name | |
docker run -p 1433:1433 --name new_container_name -td new_image_name | |
# upgrade running container | |
docker-compose up --force-recreate --build -d | |
docker image prune -f | |
# ======= | |
# Volumes | |
# ======= | |
# create | |
docker volume create volume_name | |
# list | |
docker volume ls | |
# =========== | |
# Interactive | |
# =========== | |
docker exec -it container_name bash | |
docker exec -u 0 -it container_name bash # login as root | |
# copy a file from host to container | |
docker cp foo.txt container_name:/foo.txt | |
# copy a file from Docker container to host | |
docker cp container_name:/foo.txt foo.txt | |
# login to mssql | |
docker exec -it mssql1 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P password | |
# export container contents | |
docker export container_name > tar_file.tar # tar -xf tar_file.tar | |
# ==== | |
# Logs | |
# ==== | |
# view container logs | |
docker logs container_id | |
# ==== | |
# Misc | |
# ==== | |
# create mssql | |
# -v is volume_name:container_location (optional) | |
# -d is detached mode (required so it runs as a docker background process) | |
# -p is host_port:container_port | |
docker run \ | |
-e 'ACCEPT_EULA=Y' \ | |
-e 'MSSQL_PID=Express' \ | |
-e 'MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>' \ | |
-p 1433:1433 \ | |
-v mssql1data:/var/opt/mssql \ | |
-d \ | |
--name 'mssql1' | |
mcr.microsoft.com/mssql/server:latest | |
/opt/mssql/bin/mssql-conf set filelocation.defaultbackupdir /var/opt/mssql/backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment