Here's a terminal guide to pull the Docker Ubuntu image and run it from the terminal in macOS:
1. Install Docker Desktop:
- Download Docker Desktop for Mac from https://www.docker.com/products/docker-desktop
- Follow the installation instructions, which typically involve dragging the Docker icon to your Applications folder and starting it.
2. Pull the Ubuntu image:
- Open a terminal window (Applications > Utilities > Terminal).
- Run the following command to pull the latest Ubuntu image:
docker pull ubuntu
3. Run the Ubuntu container:
- Execute the following command to start an interactive Ubuntu container:
docker run -it ubuntu /bin/bash
Explanation of flags:
-it
: Allocates a pseudo-TTY and keeps STDIN open, allowing interactive terminal use.ubuntu
: Specifies the Ubuntu image to run./bin/bash
: Launches the Bash shell within the container.
4. Work within the container:
- You'll now be inside the Ubuntu container's Bash shell.
- Use Ubuntu commands as you would on a regular Ubuntu system.
- To exit the container, type
exit
.
Additional notes:
- To view running containers, use
docker ps
. - To stop a container, use
docker stop <container_id>
. - To remove a container, use
docker rm <container_id>
. - To list available images, use
docker images
. - To remove an image, use
docker rmi <image_id>
.
I'll provide instructions for reconnecting to the same terminal session in different scenarios:
1. Disconnected SSH session:
If the session is still active on the server:
If the session has terminated:
2. Closed terminal window:
tmux attach
screen -r
3. Reconnecting within Docker:
To reattach to a running Docker container:
docker attach
command:To start a new interactive session in a running container:
docker exec
command:4. Reconnecting to a local terminal session:
5. Specific terminal emulators:
General tips:
-o ServerAliveInterval=60
option with SSH to send keep-alive messages.