Useful commands:
$docker ps = list running docker containers
$docker exec -it b62d2878e0cb sh = connect to container ID b62d2878e0cb ==> run a container with no options and by default you have a stdout stream (so docker run | <cmd> works); run with -i, and you get stdin stream added (so <cmd> | docker run -i works); use -t, usually in the combination -it and you have a terminal driver added, which if you are interacting with the process is likely what you want. It basically makes the container start look like a terminal connection session.
$docker system prune = pruning old docker images to free up disk space on container
$docker container stop container_name= Stop a running container through SIGTERM
$docker container kill container_name= Stop a running container through SIGKILL
$docker network ls = List the networks
$docker container ls = List the running containers (add --all to include stopped containers)
$docker container rm -f $(docker ps -aq) = Delete all running and stopped containers
$docker container logs --tail 100 containerID = Print the last 100 lines of a container’s logs
$docker volume create app-volume = create a separate app-volume so that when you re-create your docker container the files you where working on are saved and can be re-attached to the new container
$docker run --name=mk-mysql -p3306:3306 -v app-volume:/path/to/app-volume -e MYSQL_ROOT_PASSWORD=my- secret-pw -d mysql/mysql-server:8.0.20 ==> This command will pull the MySQL server version 8.0.20 from the Docker registry and then instantiate a Docker container with the name “mk-mysql.” It will also attach the previously created volume “app-volume” with the Database and will expose the port 3306 so that you can reach the MySQL database outside the container
Linux Alpine
$apk add nano = install nano on ECS EC2 instance
Run a container from the Alpine version 3.9 image, name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container.
$docker container run --name web -p 5000:80 alpine:3.9
References:
Connect to mysql running in docker container from local machine:
https://towardsdatascience.com/connect-to-mysql-running-in-docker-container-from-a-local- machine-6d996c574e55