Docker Installation/Setup in Ubuntu

Installation
————-

Update your droplet:

$ sudo apt-get update
$ sudo apt-get -y upgrade

Make sure aufs support is available:

$ sudo apt-get install linux-image-extra-`uname -r`

Add docker repository key to apt-key for package verification:

$ sudo apt-key adv –keyserver hkp://pgp.mit.edu:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Add the docker repository to Apt sources:

$ echo “deb https://apt.dockerproject.org/repo ubuntu-trusty main” | sudo tee /etc/apt/sources.list.d/docker.list

Update the repository with the new addition:

$ sudo apt-get update

Finally, download and install docker:

$ sudo apt-get install docker-engine

Edit UFW (Uncomplicated Firewall) configuration using the nano text editor.

$ sudo nano /etc/default/ufw

Replace: DEFAULT_FORWARD_POLICY=”DROP”
With: DEFAULT_FORWARD_POLICY=”ACCEPT”

Finally, reload the UFW:

$ sudo ufw reload

Using Docker
————

To run the docker daemon:

$ sudo docker -d &

For system-wide information on docker:

$ sudo docker info

For docker version:

$ sudo docker version

Working with Images
——————-

Searching for a docker image:*

$ sudo docker search ubuntu

Downloading (PULLing) an image:

# Usage: sudo docker pull [image name]

$ sudo docker pull ubuntu

Listing images:

$ sudo docker images

INFO[4160] GET /v1.21/images/json
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              latest              e9ae3c220b23        10 days ago         187.9 MB
hello-world         latest              0a6ba66e537a        5 weeks ago         960 B

Committing changes to an image:

# Usage: sudo docker commit [container ID] [image name]

$ sudo docker commit 8dbd9e392a96 my_img

Sharing (PUSHing) images:

$ sudo docker push my_username/my_first_image

Working with Containers
———————–

Use the following command to list all running containers:

$ sudo docker ps

To have a list of both running and non-running ones, use:

$ sudo docker ps -l

Creating a New Container

To create a new container, you need to use a base image and specify a command to run.

# Usage: sudo docker run [image name] [command to run]

$ sudo docker run ubuntu echo “hello”

# Usage: sudo docker run –name [name] [image name] [comm.]

$ sudo docker run –name=test ubuntu echo “hello”

Running a container:

# Usage: sudo docker run [container ID]

$ sudo docker run c629b7d70666

Stopping a container:

# Usage: sudo docker stop [container ID]

$ sudo docker stop c629b7d70666

Removing / Deleting a container:

# Usage: sudo docker rm [container ID]

$ sudo docker rm c629b7d70666

Upgrade Docker
————–

$ curl -sSL https://get.docker.com/ | sh

Uninstallation
————–

To uninstall the Docker package:

$ sudo apt-get purge docker-engine

To uninstall the Docker package and dependencies that are no longer needed:

$ sudo apt-get autoremove –purge docker-engine

If you wish to delete all images, containers, and volumes run the following command:

$ rm -rf /var/lib/docker

You must delete the user created configuration files manually.

Ref: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started

Leave a Reply

Your email address will not be published. Required fields are marked *