OneBite.Dev - Coding blog in a bite size

use docker

Simple docker step by step how to use docker with explanation

Docker is a piece of technology that helps you create, deploy, and run applications smoothly by using containers.

In essence, it’s a tool made for developers to squeeze out maximum productivity. So, let’s dive right into this simple, step-by-step tutorial on how to use Docker.

Getting Set Up

First, you need Docker on your system, right? Just swing by Docker’s website and download the version that’s correct for your operating system.

Once you’ve downloaded it, just follow the installation wizard. At the end, it’ll ask you if you want to use the default Unix socket or the Connect with TCP option for Docker.

Select the Unix socket option. Feel free to leave everything else as is. After that, just hit ‘Install’ and wait a moment.

Saying Hello to Docker World

Much like the programming tradition of ‘Hello World’, let’s have Docker give a shoutout to the world.

Open your terminal and type docker run hello-world.

This command checks whether Docker is correctly installed and working well on your system. You should see a message showing Docker is running correctly.

Managing Docker Images

Docker images are a big deal. They’re the basis for containers. Think of them as the blueprint. To download an image, use the docker pull command followed by the image’s name. For instance, to download Ubuntu image, type docker pull ubuntu in your terminal.

Running Docker Containers

With an image at hand, now’s the time for the real deal. To create a container, type docker run -it ubuntu bash. The -it flag makes the container interactive.

Container Operations

Now that you have a running container, you can operate it using several commands:

  • List containers: docker ps -a lists all containers (including inactive ones).
  • Stop a container: docker stop container_id stops a running container. Swap ‘container_id’ with your container’s ID.
  • Remove a container: docker rm container_id does just what it says. It removes the specified container.

Building a Docker Image

Let’s build an image. Create a directory and a ‘Dockerfile’ inside it. In the file, you define your image. For instance, if you’ve an application that runs on Node.js, your Dockerfile may look like this:

FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]

Once your Dockerfile is ready, build the image using docker build -t your_image_name ..

So, there you have it. A step-by-step guide to start your journey with Docker. Don’t be shy to tinker around; the best way to learn is by doing. Happy Docker-ing!

docker