Ruben's Blog | ีีธึีขีฅีถีซ ิฒีฌีธีฃีจ
๐ ..Tips on troubleshooting Docker Image build, Compose and Swarm issues ๐ณ๐ณ๐ณ
Docker has revolutionized the way we develop, deploy, and manage applications, allowing us to create lightweight and isolated containers that encapsulate our applications’ dependencies and runtime environments. However, like any technology, Docker can present its fair share of challenges. In this blog post, we will delve into the world of troubleshooting Docker image builds, Docker Compose, and Docker Swarm failures, and explore some troubleshooting techniques I use that may help you save time.
Dockerfile
Troubleshooting docker image “build failed”
Let’s say we have a Dockerfile which doesn’t build. Let’s say it looks like this.
FROM ubuntu
RUN echo "build started"
RUN apt install -y curl
RUN echo "build finished"
The output will look something like this.
Let’s say we don’t understand why it’s failing, though in this case it’s written clearly.
we can do following, comment out all the lines in the dockerfile up to the point of failing line.
FROM ubuntu
RUN echo "build started"
# RUN apt install -y curl
# RUN echo "build finished"
build it docker build -t test-image .
Run image and shell into it docker run -it test-image bash
.
Explore the image from the inside and try to fix the issues.
and now if we do apt install -y curl
it’s finally installed.
So we put the fix in the dockerfile and everything builds normally.
Compose
Troubleshooting docker compose doesn’t start properly
If you don’t understand why your servers are not starting and you are at a dead end, you can always comment it out. Start by commenting one by one and running after each change to troubleshoot
- networks
- ports
- volumes
- Containers that depend on other containers
Swarm with compose
Common reasons why your docker-compose may work on it’s own and not work with the swarm
Networking issue
- Note that docker swarm cannot allocate a static IP to a machine, the main reason is that if there is more than 1 server it will not know to which server to allocate it.
- You can try commenting on all network parameters in compose file.
Volume issue
- If you use virtual volumes in most cases you will not get a problem, otherwise, docker swarm will not start, the issue is that in the secondary nodes volume will not be found.
There are 2 solutions to this problem
- Use virtual volumes
- Create directories and provide absolute paths to the volume.
volumes: - /absolute-path-to-volume:/app/data
Exposed Ports issue
- Try commenting out exported ports in docker compose.
- There might be some network misconfiguration
- Another possibility is another server docker or a non-docker is running. In this case, you will need to disable the server or change the exposed ports.
ENV variables
- You cannot use
env_file:
when running docker swarm, the reason is that on the secondary nodes, you may not have the file, and thus docker cannot read it, useenvironment:
instead- I actually wrote a script in Makefile that created a temporary docker compose infused in env variables from
.env
file. It was junky๐๏ธ but it worked.
- I actually wrote a script in Makefile that created a temporary docker compose infused in env variables from
Troubleshooting docker swarm amd docker compose
If you run docker swarm with docker compose and when you do docker service ls
you see that your services may not start. In that cases, you can investigate the service manually.
docker service ps --no-trunc DOCKER_SERVICE_CONTAINER_ID
This command helped me in numerous cases๐๏ธ when I didn’t understand what is wrong with the swarm!
Docker will tell you about the issue. If it’s a network issue try
docker network list
And after you can continue investigating with
docker network inspect DOCKER_NETWORK_ID
Finally ๐ฌ
If you don’t understand the issue, comment something out and run it.
Please give me feedback, comment on whatever you think about my blog post, and help me improve. โค๏ธ
Blog Menu
- ๐ผ hire my consultancy
- โน๏ธ about me
- ๐ฐ rss
- ๐ธ a young blog
- ๐ blog
- 2024-10-28
Engineering Solution to Every Problem โ๏ธ
As an engineer, I strive to find engineering solutions to every problem surrounding me, engineering doesn’t mean technical in this case. There a...
- 2024-10-27
I'm Going to Invest in Podcasting More ๐ค
Podcasting is discovery It’s listening to so many familiar and different ideas and being able to ask questions, where people can answer you live...
- 2024-10-26
Scooping Motivation ๐ฆ๐ฉ
For me, motivation is being on the edge. I need to feel that what I do is important to do, at that exact moment. (Probably because of my ADHD) There i...
- 2024-10-24
Reflection on My Journey ๐ญ
You can recover your journey from the history of my blog posts if you have been following, though you also probably know that I don’t need peopl...
- 2024-10-22
A Step a Day Adds Up to a Mile ๐ถ๐ปโโ๏ธ
I had a meeting with important people. All people are important, these ones are important to me. This was my target a couple of months ago, does this ...
- 2024-10-21
Toastmaster ๐ท
I was at a party another day, there was a toastmaster, he was doing his job. I’m not here to judge but to observe. Toastmasters’ direct mo...
- 2024-10-19
The Meaning ๐ฌ๏ธ
I wrote about this again, but investing time in meaningful connections is crucial. It’s not just spending; it’s a real investment. You can...
- 2024-10-18
Complexity in Multi-model Architectures ๐
I can move from cities and even to countries with a single backpack and or a single hanger with a couple of clothes, be able to attend the event, and ...
- 2024-10-18
Buying Problems ๐
I must always remember that buying into any relationship, be that business, employment, or personal once, you are always buying problems first. It&rsq...
- 2024-10-16
Every Company Is Different ๐คฆ๐ปโโ๏ธ
Doing the podcasts I talk to different friends from tech and other industries. There are so many approaches, and so many different opinions, there is ...
- See all...
- ๐ links