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-12-29
Then the Journey Is Not About Winning ๐๏ธ
Winning is the target, but the journey is never about winning. You cannot be sure the path is correct. Even with guidance, there is a chance it’...
- 2024-12-28
Free Consultancy ๐๐ป
Nobody buys it. When I provide it everyone is happy. Why? Maybe people don’t understand the offer, which is completely understandable. What I of...
- 2024-12-28
The Algorithm of the Dressings ๐ฅฌโ๐ฅโโ๏ธ๐ฐ๐ฅ
Martun said he read many books about healthy food and didn’t become healthy. I agree, that reading and doing is very different. But I think that...
- 2024-12-25
Powered.community Meetup ๐ค๐ป
Well, it happened. The food was sushi, and people came with friends, some just checking in. I was so glad to see so many people I know and don’t...
- 2024-12-23
5 Books to Read Before 2025 to Transform Your Life ๐๏ธ
People are not computers, though we share traits such as short and long-term memory or processing power. You cannot install a “software” o...
- 2024-12-21
Ikigai ๐ฅ
Opportunities come and go, but sometimes there is THAT opportunity. It makes my heart sing, puts me in sync with what I live for, and creates purpose ...
- 2024-12-19
Piece Is Pressure
We are not in a hot war right now, but it’s always over the corner. Many countries are in hot wars at this moment, what do they tell us? What wo...
- 2024-12-17
I Met My Mentor ๐ฆ
My mentor probably doesn’t know she is my mentor. And I understood some things. I did a lot of analysis. She told me about the start stop and co...
- 2024-12-17
I'm Still Learning ๐
I find myself suggesting the right solutions, right for me. And when I see that the pattern doesn’t match, I get sad. It’s hard to acknowl...
- 2024-12-13
Rushing the Process Doesn't Help โ๏ธ
I’ve started too late, because of that I have more knowledge from the field. I have been learning these past 4 years, but starting something by ...
- See all...
- ๐ links