What you need to know about Docker

The Docker ecosystem and how to start with it

Besmire Thaqi
FAUN — Developer Community 🐾

--

Photo by Jacob Meissner on Unsplash

Let’s start with the famous phrase “based on a true story”.

Working in a startup is messy. Lots of requirements, new features all the time, new tools and technologies to deal with. This means that you’re adding more complexity to your project.

The harder it is to set up your project, the worse for you and your colleagues. As my dear colleague would say: “If we cannot start the project with one command, we’re in trouble”.

As developers with the same KISS (Keep It Simple, Stupid) principle, we want to simplify our current setup. Run everything in one command, or two, whatever.

Docker to the rescue! 🐳

The before-mentioned situation is one of the many reasons why you should learn about Docker and containers. These tools are the new way of running software and the new revolution of the software development cycle.

What the fuss is all about

A lot of big companies put trust in Docker for many reasons. Business-wise it is on budget, it offers security and it’s very compatible.

Docker Ecosystem ♻️

It contains docker file, images, containers, and volumes. Docker files are files with instructions to create images.

An image; like in old times, serves like a CD or USB with the tools, libraries you need to run your app. Images are with all the necessary things we need to run our app. If we want to run an image, we would deploy it in the container.

Containers can be created, destroyed, and created again anytime we want without losing anything. You can think of it as a VM but smaller and independent from your current OS.

If you need multiple containers, you also need multiple docker commands. Therefore; sometimes it’s hard to remember these commands. Thus; docker-compose allows us to use a .yml file, and this will run all docker commands you need.

You don’t need to remember parameters, just put them on the file!

Get started with Docker

Let’s get to know our steps to start with the Docker environment! 🌟

1. Download and Install Docker

Make sure to install a maintained version of Docker from Docker Community Edition (DE) or Enterprise Edition (EE): https://docs.docker.com/install/

2. Test Docker Version and Installation

Run the following command to check if you have a supported version:

docker --version
Docker version 18.09.2, build 6247962

Check more information regarding the installation:

docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.2
...

Test that your installation was successful:

docker run myapp
Unable to find image 'myapp:latest' locally
docker: Error response from daemon: pull access denied for myapp, repository does not exist or may require 'docker login'.
See 'docker run --help

3. Create the Dockerfile

Let’s start by specifying the base image in the Dockerfile. In this case, we’re pulling from Python3 base image:

# Pull official base image
FROM python:3

The next step is writing commands for copying the files and installing the dependencies and we set a working directory to copy all the files of our app:

RUN mkdir /myapp
WORKDIR /myapp
COPY requirements.txt /myapp/
RUN pip install -r requirements.txt
COPY . /myapp/

4. Commands Cheat Sheet

## List docker commands
docker
## List docker images
docker image ls
## List docker containers (currently running, all)
docker container ls
docker container ls --all
## Build docker images from Dockerfile, docker-compose.yml
docker-compose up -d
## Run docker image
docker run <my-app>
## Login with docker credentials
docker login
## Remove a docker image
docker image rm <image id>
## Remove a docker container
docker container rm <hash>
## Stop, kill a docker container
docker container stop <hash>
docker container kill <hash>

A short recap

Docker is a new technology that allows development teams to build and manage secure apps. A docker container can be seen as a computer in your computer. It makes your app independent from your current OS.

Most importantly, this technology is open source!

👋 Join FAUN today and receive similar stories each week in your inbox! Get your weekly dose of the must-read tech stories, news, and tutorials.

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--