Kickstart Docker Container on Ubuntu
I have an idea regarding what’s Docker is. I keep on hearing and reading about it across communities. Since I am also an IT person, I have started to deep dive into Docker.
This is a guide to get started with using Dockers. First of all, here is my system spec with which I am playing.
Ubuntu 18.04 Bionic
First of all, remove any trace of existing installation in case you have too played earlier but left the game in between :).
$ sudo apt-get remove docker docker-engine docker.io
Now, add docker APT repository to get the latest docker engine instead of using Ubuntu official repository.
$ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common # Add APT key $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # Verify key $ sudo apt-key fingerprint 0EBFCD88 # Add repo $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" $ sudo apt-get update
Install docker community edition.
$ sudo apt-get install docker-ce
Now, let’s verify if installation went fine by spawning a new container.
$ sudo docker run hello-world Hello 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. (amd64) 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
docker run command is a sequence of two commands i.e. create and start container. If there is no service that keeps on running in foreground, then container will shutdown after start.
Above will create a new container that can be simply started again instead of creating new one. Following lists all containers created
$ sudo docker container ls --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d5ee7808b004 hello-world "/hello" 7 hours ago Exited (0) 2 minutes ago festive_villani
Now, let’s run a container and login to it.
$ sudo docker run -it ubuntu bash root@06ea4e086c3c:/# hostname -f 06ea4e086c3c root@06ea4e086c3c:/#
Thank you guys for reading. Have a nice day 🙂