DEV Community

Cover image for Wtf is Docker🐳?
Erlan Akbaraliev
Erlan Akbaraliev

Posted on

Wtf is Docker🐳?

Docker is a software that makes our app run on any machine, so our app always runs, always works.

Without this magic app, we can often get "The app works on his laptop, but doesn't work on mine😭, wtf?"
If we use Docker to run our app, we'll never have the "works on his, not on mine" problem again. 2-3 years in Dagestan/Docker - and forget!
Khabib aka

Let me show it in practice:
1. Make a website

  • $ python3 -m venv .venv
  • $ source .venv/bin/activate
  • $ python3 -m pip install Django
  • $ django-admin startproject app
  • $ cd app
  • $ python3 manage.py runserver Open http://localhost:8000/ on your browser Django runserver This means your Python-based website is now running using the Django framework. Don't know what a framework is? Get the f*** outta here!

2. Prepare Dockerfile (configuration file for docker)

  • $ pip freeze > requirements.txt
  • Create a Dockerfile yourself or use the command $ touch Dockerfile
  • Copy paste the below configuration into Dockerfile
FROM python:3.13
WORKDIR /apps
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
Enter fullscreen mode Exit fullscreen mode

3. Install Docker desktop and keep it open
https://www.docker.com/products/docker-desktop/

4. Put your project into a container and run your project as a container

  • $ docker --version
  • $ docker build -t my_docker .
  • $ docker images
REPOSITORY TAG    IMAGE         CREATED          SIZE
my_docker latest 6aeb9f9143b About a minute ago 1.77GB
Enter fullscreen mode Exit fullscreen mode
  • $ docker run -p 8000:8000 my_docker Docker container result

That's it!
Your website is now running inside a container, which ensures it will work on everyone's laptop - as long as you share the container that includes your app.
Duhh
In the real world, developers share their containers with a virtual machine that runs 24/7, keeping the website available to the world.

Why share it?

Because using containers means you'll never have to worry about your project not running properly. That's literally the main reason Docker exists - so your app always works. Period.

Things to remember

  • Dockerfile defines how to containerize your project. It specifies which OS to use (Mac, Windows, Linux), which Python version to install, and how to run your project.
  • $ docker build -t my_docker . To build an image (a thing needed to build/make a container of our project)
  • $ docker images List all the images (a thing needed to build/make a container) we have
  • $ docker run -p 8000:8000 my_docker Runs our containerized project on port 8000 of our computer

In conclusion, the best way to make your terrible code run on everyone's laptop - containerize it😚.
End

Top comments (0)