Installing Docker in macOS, the official document seems to recommend installing Docker Desktop with the installer. I don’t need desktop function so far, but this is not so critical when I learn Docker. And it is the easiest way to install Docker CLI in macOS. If you don’t have DockerID, please make it first.
Related official Documents:
Don’t forget that you need to exec docker once because of permissions of macOS.
Follow official instructions.
sudo apt install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER
I don’t use GUI feature. Therefore the following intro is performed on a terminal.
docker pull ubuntu:latest
Caution: Not /
but :
.
docker run -it --name="UbuntuBase" ubuntu/latest
This command retrieves the imageubuntu/latest
automatically and runs the container.
Notes: If you want to share a directory, using -v
.
docker run -it -v /vagrant:/tmp/shared --name="myContainerName" ubuntu:latest
Imagine the container -> what is the difference between start, exec and run.
If you type exit
inside the container which is running with -it
, the container stops.
If you want to attache it again, you should start the container first and attach to it.
(exit)
docker start UbuntuBase
docker attach UbuntuBase
The meaning go option -it
are
https://docs.docker.com/engine/reference/commandline/attach/ If the container was run with -i and -t, you can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.
start
, exec
, run
start
: start one or more stopped containers.exec
: Run a command in a running container. With -it and bash command, it looks very similar to start.run
: Run a container from an image.docker commit 462f07f7b4c6 atlex00/ubuntu_updated
docker stop
stop one or more running containers.
docker stop UbuntuBase
Notes: https://stackoverflow.com/questions/51466148/pause-vs-stop-in-docker
docker push atlex00/ubuntu_updated
Run docker container with port mapping localhost:53306 to container 3306.
docker run --name mysql-test -e MYSQL_ROOT_PASSWORD=temp-root -d -p 53306:3306 mysql:8.0
Show docker containers
docker -a