Skip to content

pwittchen/learning-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

learning-docker

Repository created in order to learn basics about Docker

Overview

A container is a stripped-to-basics version of a Linux operating system. An image is software you load into a container. Docker lets people (or companies) create and share software through Docker images. Using Docker, you don't have to worry about whether your computer can run the software in a Docker image - a Docker container can always run it.

docs.docker.com

Contents

Installation on Linux

Install Docker with the following command:

$ wget -qO- https://get.docker.com/ | sh

to see if docker was installed type:

$ docker

To see if the sample docker image was loaded and executed type:

$ sudo docker run hello-world

If everything works, you should see Hello from Docker message and some other stuff. It means Docker was installer properly.

There's also another tutorial showing Docker installation at: https://docs.docker.com/engine/installation/linux/ubuntulinux/

Installation on OS X

Docker Toolbox

NEW Update!

Now, we can simple install Docker for Mac on macOS and it works out of the box.

Update!

On OS X we can also use Docker Toolbox, which provides all functionality and Docker installation "out-of-the-box". Tutorial showing, how to install and run it is available at: https://getcarina.com/docs/tutorials/docker-install-mac/.

Note: For me it didn't work with iTerm. I needed to use default terminal available in OS X.

Manual installation

Install Homebrew and then:

$ brew install cask
$ brew cask install virtualbox
$ brew install docker
$ brew install boot2docker
$ boot2docker init
$ boot2docker up

After running boot2docker up, you'll see instructions, which will show you, what to do to finish installation. You can add the following variables to your .zshrc or .bashrc file:

export DOCKER_HOST=tcp://YOUR_IP:2376
export DOCKER_CERT_PATH=/Users/YOUR_USER_ID/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1

If everything is fine, you can start Ubuntu shell as follows:

docker run -i -t ubuntu /bin/bash

Use Ctrl+D to exit.

For more details, read this article: http://penandpants.com/2014/03/09/docker-via-homebrew/

Docker images

Docker images can be downloaded from Docker Hub. We can search, download and run different images.

To run sample image type:

$ sudo docker run docker/whalesay cowsay boo

To see installed images type:

$ sudo docker images

Creating Docker image

In a separate directory create file named Dockerfile with the following content:

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay

Build docker image with the following command:

$ sudo docker build -t docker-whale .

There's period . in the end and docker-whale is name of created docker image.

Short description of commands:

  • FROM keyword tells Docker which image your image is based on
  • RUN is used to install required software
  • CMD is used to run the software

To verify whether image is built, run:

$ sudo docker images

and check if docker-whale image is listed.

To run image, type:

$ sudo docker run docker-whale

Pushing image to Docker Hub

Create account on Docker Hub and Create new repository named docker-whale

List your images:

$ sudo docker images

You should see something like:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker-whale        latest              30d13636f688        8 minutes ago       274 MB
hello-world         latest              af340544ed62        8 weeks ago         960 B
docker/whalesay     latest              fb434121fc77        4 months ago        247 MB

Copy IMAGE_ID of your image and type (use your own login here):

$ sudo docker tag 30d13636f688 pwittchen/docker-whale:latest

Type sudo docker images to see if your image is tagged.

REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker-whale             latest              30d13636f688        9 minutes ago       274 MB
pwittchen/docker-whale   latest              30d13636f688        9 minutes ago       274 MB
hello-world              latest              af340544ed62        8 weeks ago         960 B
docker/whalesay          latest              fb434121fc77        4 months ago        247 MB

Login to Docker Hub with the following command:

$ sudo docker login --username=yourhubusername --password=yourpassword --email=youremail@company.com

Push your image to Docker Hub with the command (use your own login here):

$ sudo docker push pwittchen/docker-whale

Go to Docker Hub website and check if your image is there.

Pulling image from Docker Hub

Use docker rmi command to remove docker-whale and pwittchen/docker-whale iamges:

$ sudo docker rmi -f 30d13636f688
$ sudo docker rmi -f docker-whale

Pull your image:

$ sudo docker pull pwittchen/docker-whale

Run your image:

$ sudo docker run pwittchen/docker-whale

Sample Dockerfiles

dockerfiles directory contains sample Docker configurations.

  • whalesay - hello world sample with cowsay and fortune script from tutorial
  • ubuntujava - ubuntu container with java and related tools

You can use Makefile located in each directory to build, run and clean (remove) Docker image defined in Dockerfile:

  • make build creates container
  • make run runs container
  • make clean removes container
  • make list lists all containers

References

About

learning basics of Docker

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages