This article provides a guide on installing Docker on an Ubuntu virtual machine and running Docker containers.
Welcome to this comprehensive guide on installing Docker on an Ubuntu virtual machine. In this lesson, we will cover the process of setting up an Ubuntu VM, installing Docker, and running Docker containers.
Ensure that you are connected to your Ubuntu VM via SSH from your laptop before proceeding.
Install Docker by using the apt-get package manager to install the Docker package (docker.io). This command will install Docker along with all the necessary dependencies.
Copy
Ask AI
bashroot@osboxes:/home/osboxes# apt-get install docker.ioReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: bridge-utils cgroupfs-mount containerd git git-man librerror-perl runc ubuntu-fanSuggested packages: aufs-tools btrfs-tools debootstrap docker-doc rinse zfs-fuse | zfsutils git-daemon-run | git-daemon-svn git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svnThe following NEW packages will be installed: bridge-utils cgroupfs-mount containerd docker.io git git-man librerror-perl runc ubuntu-fan0 upgraded, 9 newly installed, 0 to remove and 387 not upgraded.Need to get 21.4 MB of archives.After this operation, 116 MB of additional disk space will be used.Do you want to continue? [Y/n]
After confirming the installation, Docker will be installed on your system. To verify the installation, display Docker’s help page by running:
Step 4: Running the “hello-world” Docker Container
Now that Docker is installed, let’s run a simple container to confirm that Docker is functioning correctly. Use the following command to run the “hello-world” container. This command will automatically pull the image from Docker Hub if it is not already available locally, and then display a confirmation message.
Copy
Ask AI
root@osboxes:/home/osboxes# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldca4f61b1923c: Pull completeDigest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7Status: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bash
For a bit of fun, let’s run another Docker image called “whalesay.” This container uses the “cowsay” program to display a message along with an ASCII art whale. Execute the command below:
Copy
Ask AI
root@osboxes:/home/osboxes# docker run docker/whalesay cowsay booUnable to find image 'docker/whalesay:latest' locallylatest: Pulling from docker/whalesay903dcd34cfd7: Pull complete00bf65475aba: Extracting [==================> ] 16.12 MB/37.71 MBa3ed95caeb02: Pull completec57b6bbc83e3: Download complete8978f6879e2f: Download complete8eed3712d2cf: Download complete
Once the image is pulled, the container runs and produces the following output: