Why does my Docker container only ping once after reboot?

0
0
Asked By TechSavvyJohnny43 On

Hey everyone! I'm trying to learn Docker on my Ubuntu laptop and made a simple Dockerfile to ping 8.8.8.8. When I run my container after a fresh reboot, it pings successfully the first time, but on subsequent attempts, I get 100% packet loss. Here's my Dockerfile:

```
FROM alpine
RUN apk add python3
CMD ["8.8.8.8"]
ENTRYPOINT ["ping", "-c", "5"]
```

After building the image with `docker build . -t myweb:3`, it works great at first. However, every time I try to run it again, I face packet loss. I've even checked the network settings and created a custom network, but I'm still stuck.

I noticed that if I ping google.com instead, it tries to use IPv6 and I run into the same issue. I'd appreciate any advice on what might be going wrong. Thanks!

3 Answers

Answered By CodeWizard22 On

Have you tried running the ping command natively in an Alpine container first? Pinging public IPs can sometimes be tricky since many sites like Google block ICMP requests to avoid attacks. It might not even be a container issue, but rather how Google sees your requests. A tool like curl would be better for checking URL access instead of pinging directly.

TechSavvyJohnny43 -

I can ping google.com fine from my terminal, but I see what you mean about the ICMP requests.

Answered By DockerNinja88 On

Consider swapping your CMD and ENTRYPOINT around. The ENTRYPOINT is for setting up the executable, while CMD should handle parameters you want to pass. And why add Python if all you're needing is to ping? Just a curious thought!

TechSavvyJohnny43 -

Good point! I’m following a course on Udemy, and I guess that was just a step in their setup.

Answered By NetworkingExpert99 On

Try running this command directly in your terminal:

```
docker run -it --rm alpine ping google.com
docker run -it --rm alpine ping google.com
```
See how that behaves for you.

TechSavvyJohnny43 -

I’ll give that a shot! Just to clarify, should I put that in the CMD section for my Dockerfile?

NetworkingExpert99 -

No, run those directly in your terminal. Let me know what happens!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.