Skip to content

Instantly share code, notes, and snippets.

@Prajwal-Koirala
Created January 20, 2024 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prajwal-Koirala/6055d0e32e02f72d0bbec913d2d509f0 to your computer and use it in GitHub Desktop.
Save Prajwal-Koirala/6055d0e32e02f72d0bbec913d2d509f0 to your computer and use it in GitHub Desktop.

Here's a terminal guide to pull the Docker Ubuntu image and run it from the terminal in macOS:

1. Install Docker Desktop:

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>.
@Prajwal-Koirala
Copy link
Author

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:

    • Open a new terminal window and use the same SSH command you used previously to connect.
    • You should be reconnected to the same session.
  • If the session has terminated:

    • You'll need to start a new SSH session and resume your work.

2. Closed terminal window:

  • Using terminal multiplexers (tmux or screen):
    • If you started the session within a terminal multiplexer, you can reattach to it using:
      • tmux attach
      • screen -r

3. Reconnecting within Docker:

  • To reattach to a running Docker container:

    • Use the docker attach command:
      docker attach <container_id>
  • To start a new interactive session in a running container:

    • Use the docker exec command:
      docker exec -it <container_id> /bin/bash

4. Reconnecting to a local terminal session:

  • macOS Terminal app:
    • There's no built-in reconnection feature.
    • Consider using a terminal multiplexer like tmux or screen for persistent sessions.

5. Specific terminal emulators:

  • Some terminal emulators might have their own reconnection features.
  • Check the documentation for your specific emulator for details.

General tips:

  • To prevent accidental disconnections, consider:
    • Using the -o ServerAliveInterval=60 option with SSH to send keep-alive messages.
    • Enabling terminal multiplexers like tmux or screen for persistent sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment