Docker — Tutorial for Beginners

Docker Install for Debian 9

Install Prerequisites

# apt-get install apt-transport-https dirmngr

Add Docker Repository
Add Docker package depository to your /etc/apt/sources.list sources list:

# echo ‘deb https://apt.dockerproject.org/repo debian-stretch main’ >> /etc/apt/sources.list

Obtain docker’s repository signature and updated package index:

# apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D
# apt-get update

Install Docker

# apt-get install docker-engine

Simple Docker Commands

# docker run -it ubuntu bash

Download a Image from offical repository and Run. If the image has already been downloaded, just run and enter the image contaniner shell.

If you exit the shell, the container will be stopped.

# docker run -d -it ubuntu bash

Run the image container in background. If there is no image, download it

# docker exec -it <CONTAINER ID/NAME> bash

Enter the container shell. You can use container id or name.

Setting up the project

Create a file named “Dockerfile”. This file is similar to shell file. Get a ready image and run commands, then create a new image.

# docker build -t lamp .

Created a new image named “lamp”.

# docker images

You can see your new image “lamp”.

# docker run -p 80:80 -it -d lamp bash

Created a container from “lamp” image. Main machine port 80 redirected to 80.

http://<your main device ip>

If your port 80 is not avialable, you can use 8080.

# docker run -p 8080:80 -it -d lamp bash

http://<your main device ip>:8080

DevOps & Software & Architect & Linux Geek — http://baturorkun.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store