How to run an Ubuntu Docker container and access the bash shell

This basic example tutorial will run an Ubuntu Docker container and the bash shell inside. To start with, run the docker run towards Ubuntu as shown here:

sudo docker run -it ubuntu /bin/bash
  • sudo – if you are using a non-root user (which is recommended)
  • the docker run command
  • -it means to be interactive with tty
  • Then the image name docker
  • And the command you want to execute, in our case /bin/bash

Demo – docker run Ubuntu Bash shell

How to run a docker ubuntu image with bash shell
Docker run Ubuntu – access container bash shell

How to verify whether your docker Ubuntu container is running?

If you are inside the bash shell, as shown above, your container is running successfully.

Here is the command to check the container status from outside

sudo docker ps

Typical output:

dev@codetryout:~$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
8ff384b268da   ubuntu    "/bin/bash"   9 minutes ago   Up 9 minutes             great_satoshi

References: