Docker — Tutorial for Beginners

Batur Orkun
2 min readMay 8, 2019

--

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.

FROM debian:latest
MAINTAINER Name<email>
ENV DEBIAN_FRONTEND noninteractive
# Install basics
RUN apt-get update
RUN apt-get -y install libapache2-mod-php
# Expose apache.
EXPOSE 80
EXPOSE 443

# 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

--

--