Getting Started With Docker

Getting Started With Docker

·

3 min read

In 2013, Docker introduced what would become the industry standard for containers. Containers are a standardized unit of software that allows developers to isolate their app from its environment, solving the “it works on my machine” headache. Docker is the de facto standard for millions of developers today to build and share containerized apps - from desktops to the cloud.

02 (49)-png-1.png

Why Docker?

As technology continues to evolve, building apps evolved with it. Today, writing apps involves more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage creates enormous complexity. Anyone with experience building production-ready software or any kind of project would agree that most of the applications depend on specific versions of the technologies used to develop them. The application needs to be run in an environment, but the environments can vary in terms of the operating system, version, hardware, etc. For the application to work correctly, both local and production environments need to be configured with the correct versions of these services.

Things get more complex here, and the following problems arise:

  • Compatibility of each technology/service with the underlying operating system.
  • Difficulty for a new developer to set up the environment with the right OS and Service versions.

And the list goes on.

Docker's Solution

  • Docker makes use of containers and allows developers to package an application with all of its requirements and configurations, such as libraries and other dependencies and deploy it as a single package.
  • This makes the app platform-independent hence solving the operating system compatibility issue.
  • It significantly reduces set-up time since a single package is installed.
  • It allows the developer to code and test locally while ensuring consistency between development and production environments.

The list goes on, you can read more here.

Working With Docker

To see a list of docker images on your machine, run:

docker images

To run a docker image, run:

docker run IMAGE ID

To list all running containers, run the following command,

docker ps -a

s1.png

To stop any running container, run the following command.

docker stop CONTAINER ID

s2.png

Installing docker-compose

I currently use Opensuse TumbleWeed and installing docker was easy via the main repositories. The only issue I had was installing docker-compose. Thankfully there was a solution via the docker docs. view here

To install the current stable release of Docker Compose(v2.2.3):

# Create a folder for docker plugins
mkdir -p ~/.docker/cli-plugins/

# Pull the binary from github using curl and save the output as docker-compose in the pligin directory
curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose

# Apply executable permissions to the binary
chmod +x ~/.docker/cli-plugins/docker-compose

Running docker-compose --version did not work work at first. The issue was it was not saved in the 'bin' directory.

# Copy binary to '/usr/bin'
sudo cp ~/.docker/cli-plugins/docker-compose /usr/bin

# Test the installation
docker-compose --version

This should work on all Linux distributions

After a while of playing around with it, I noticed that running docker compose without the hyphen(-) works too. After going through the documentation once again, I realised that docker compose was installed as a plugin rather than a standalone executable. Copying the executable to '/usr/bin' is redundant. To test docker compose as plugin, run:

docker compose version

Screenshot from 2022-02-04 02-06-06.png From the image it can be seen that both commands work well.

Concluding Thoughts

Overall I think docker is a great technology that is making the lives of developers easier. I'm excited to learn more and discover what this great tool has to offer. Stay tuned as I will be documenting my journey in future articles. Until then, stay safe and keep coding 🔥


References

Why Docker? | Docker

8 Reasons Why Docker Matter For Devs

Compose V2 | Docker Documentation