Dockerfile Error while giving RUN command - dockerfile

I am trying to learn Docker and I am on Oracle VMware on CentOS8. I am trying to build a Dockerfile. Here is the content of the file Dockerfile:
FROM centos
RUN yum -y install httpd
When I build, it throws the error below:
[arijhit#localhost docker-images]$ docker build --tag centos_apache:v1 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM centos
---> 0d120b6ccaa8
Step 2/2 : RUN yum -y install httpd
---> Running in 1f20ba141039
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]**
The command '/bin/sh -c yum -y install httpd' returned a non-zero code: 1
Can someone please help rectify this?
Edit:
Hi #Uberhumus Here is the response from CentOS docker image for the commands you said
[arijhit#localhost ~]$ docker run -t -d centos 60566bb1a2ef808c59c0374c0e9753bc26f0098c8b54c438e7742af418beae3a
[arijhit#localhost ~]$ docker p
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
60566bb1a2ef centos "/bin/bash" 20 seconds ago Up 8 seconds laughing_greider
5d3efb03c67a nginx:alpine "/docker-entrypoint.…" 6 minutes ago Up 5 minutes 80/tcp kind_tesla
[arijhit#localhost ~]$ docker exec -it laughing_greider /bin/bash
[root#60566bb1a2ef /]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=31.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=115 time=168 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=115 time=47.3 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 31.357/82.241/168.110/61.064 ms
[root#60566bb1a2ef /]# yum check-update
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]
[root#60566bb1a2ef /]# yum -y install httpd
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0 B/s | 0 B 00:30
Errors during downloading metadata for repository 'AppStream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]

Dear All the following solved my problem.
firewall-cmd --permanent --zone=trusted --add-interface=docker0
firewall-cmd --reload
Found it here:
https://forums.centos.org/viewtopic.php?f=54&t=74270
Many thanks to everyone here...

I tried to build your Dockerfile and I've gotten an error too, albeit a different one.
Below are working Dockerfiles for CentOS 7 and CentOS 8 respectively:
FROM centos:7
RUN yum -y install httpd
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND"]
and
FROM centos:8
RUN yum clean all && \
yum -y update && \
yum -y install httpd
EXPOSE 80
ENTRYPOINT [ "/usr/sbin/httpd" ]
CMD [ "-D", "FOREGROUND"]
Let me know if either of those works for you.
Edit:
I put the prebuilt images here if you need them.
Edit 2:
If the above Dockerfiles do not build for you, then it's most likely a problem with Docker's DNS. Please follow the steps in this article to verify that hypothesis and possibly resolve the problem.

Related

docker not installed through yum in user data

this is how my user data looks like, but docker is not installed, when connecting to my ec2 machine:
sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx
what can I do?
When using user-data script you can debug what is happening by ssh connecting to the instance and check the output in cloud-init-output.log.
sudo cat /var/log/cloud-init-output.log
When doing this you'll find an strange error containing:
Jan 29 11:58:25 cloud-init[2970]: __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'sudo yum -y install dock...'
Which means that the default interpreter seems to be python and it's neccesary to start the user-data with #!/bin/bash. (See this other StackOverflow answer)
When changing the user-data to:
#!/bin/bash
sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx
it will be executed as expected and you will find nginx running on your ec2.

aws codebuild / using local redis (ubuntu image)

Getting into code build; currently looking to use redis on a local ubuntu image;
using the following script :
version: 0.2
phases:
install:
commands:
- apt update
- apt install -y redis-server wget
pre_build:
commands:
- wget https://raw.githubusercontent.com/Hronom/wait-for-redis/master/wait-for-redis.sh
- chmod +x ./wait-for-redis.sh
- service redis-server start
- ./wait-for-redis.sh localhost:6379
build:
commands:
- redis-cli info
- redis-cli info server
For now it seems to us that docker-compose is not ultimately required, we would first look into using it that way - expecting a standard ubuntu behaviour.
We're installing postgres with a similar approach, it does start properly and is fully usable.
Here we're unable to start redis properly, wait-for-redis keeps retrying (keep getting error Could not connect to Redis at localhost:6379: Connection refused)
With an ec2 linux image (yum based), we don't have such issue
What would be the correct way start redis in that ubuntu context ?
Just ran into the same problem.
When I added a cat /var/log/redis/*.log to the buildspec I discovered that Redis was not able to bind:
Creating Server TCP listening socket ::1:6379: bind: Cannot assign requested address
Further research showed this to be a known issue: https://github.com/redis/redis/issues/3241
... which can be fixed by adding these lines to the buildspec (before using redis):
- sed -i '/^bind/s/bind.*/bind 127.0.0.1/' /etc/redis/redis.conf
- service redis-server restart

Coturn Installation failed in Centos7

I followed this link https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html#centos to install turn server in centos 7. The Configuration step I gave user name and password , also gave the same port as per the guidelines.
And finally I run the comment:
"turnserver -v -r 127.1.1:2222 -a -b turnuserdb.conf -c turnserver.conf -u turn-username -r 127.1.1:2222 -p turn-password"
it showed Wrong user name in the execution.
Any idea for Coturn installation in Centos7 because i am new in webrtc...
Please follow this instruction: https://centos.pkgs.org/7/epel-x86_64/coturn-4.5.1.2-1.el7.x86_64.rpm.html
wget https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
rpm -Uvh epel-release-7-12.noarch.rpm
yum install coturn

centos7 cockpit 176 can't add remote hosts

I set up a 01-machines.json with one host (server0), I can ssh to server0 from the management node (master0). I get an error in the UI saying A compatible version of Cockpit is not installed on 192.168.66.17. It has the same exact version, so the error is misleading. I can reach the UI on server0:9090 with the same creds (cockpit/password), no that isn't the password.
{
"server0": {
"address": "192.168.66.17",
"visible": true,
"color": "green"
}
}
I don't see anything in the logs on master0 or server0 to see what is happening. The user I connect with in the UI is the same on server0, it is in the wheel group and has passwordless sudo
# ssh cockpit#192.168.66.17
cockpit#192.168.66.17's password:
Last login: Wed Oct 24 14:16:18 2018 from 192.168.0.20
[cockpit#app-node-0 ~]$ sudo su -
Last login: Wed Oct 24 14:16:58 UTC 2018 on pts/1
[root#app-node-0 ~]#
I had the same problem, and solved with this:
In master server, I installed the dashoard.
In CentOS the you can install with:
sudo yum install cockpit-dashboard
This will enable the dashboard and allow you to add new server from dashboard UI.
In all other servers, you have to install the cockpit following the official doc:
Official doc to install Dockpit
If you are running a centOS, just run:
sudo yum install cockpit
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --permanent --zone=public --add-service=cockpit
sudo firewall-cmd --reload
After this, in dashboard on master server you will be able to add the new server
With this aproach, you don't need to use the /etc/cockpit/machines.d/ json files
So, just installing cockpit doesn't include the dashboard, you need to install cockpit-dashboard as well.

Docker build has no network, but docker run has

If I want to build my Dockerfile, it can't connect to the network or at least DNS:
Sending build context to Docker daemon 15.95 MB
Sending build context to Docker daemon
Step 0 : FROM ruby
---> eeb85dfaa855
Step 1 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
---> Running in ec8cbd41bcff
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/InRelease
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/InRelease
W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/Release.gpg Could not resolve 'httpredir.debian.org'
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/Release.gpg Could not resolve 'httpredir.debian.org'
W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg Could not resolve 'security.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package build-essential
INFO[0001] The command "/bin/sh -c apt-get update -qq && apt-get install -y build-essential libpq-dev" returned a non-zero code: 100
But if I run exactly the same command via docker run it works:
docker run --name="test" ruby /bin/sh -c 'apt-get update -qq && apt-get install -y build-essential libpq-dev'
Does anybody have an idea, why docker build does not work? I have tried all DNS related tipps on StackOverflow, like starting docker with --dns 8.8.8.8 etc.
Thanks in advance
Check what networks are available on your host with the below command:
docker network ls
then pick one that you know is working, the host one could be a good candidate.
Now assuming you are in the directory where it is available your Dokerfile, build your image appending the flag --networks and change the <image-name> with yours:
docker build . -t <image-name> --no-cache --network=host
Docker definitely seems to have some network issues. I managed to fix this problem with
systemctl restart docker
... which is basically just the unix-level 'restart-the-daemon' command in Debian 8.
I had similar problem. But as I was running AWS linux i had no systemctl. I solved using:
sudo service docker restart
My docker build also failed while trying to run apt-get upgrade with the exact same errors. I was using docker-machine on Mac OSX and a simple docker-machine restart default solved this issue. No idea what initially caused this, though.
Another case of the above reported behaviour - this time building a docker image from Jenkins:
[...]
Step 3 : RUN apt-get update && apt-get install -y curl libapache2-mod-proxy-html
---> Running in ea7aca5dea9b
Err http://security.debian.org jessie/updates InRelease
Err http://security.debian.org jessie/updates Release.gpg
Could not resolve 'security.debian.org'
Err http://httpredir.debian.org jessie InRelease
[...]
In my case it turned out that the DNS wasn't reachable from within the container - but still from the docker host !? (The containers resolver configuration was okay(!))
After restarting the docker machine (a complete reboot - a 'docker.service restart' didn't do the trick) it's been working again.
So one of my activities (or of a colleague of mine) must have broken the docker networking then !?? Maybe some firewalld modification activity ???
I'm still investigating as I'm not sure which activity may have corrupted the docker networking then ...
I have the exact same issue with a Raspberry.
Start/stopping the service did not help, but re-installing the package (dpkg -i docker-hypriot_1.10.3-1_armhf.deb && service docker start in my case) immediately solved the situation : apt-get update manages to resolve and reach the servers.
There must be some one-shot actions in the installation process...
Also faced the same issue today. My workaround was to restart your docker-machine. In my case, it's on VirtualBox.
Once you power off it and then restart the machine, http://security.debian.org seemed resolved.
Hope this helps.
A couple of suggestions, not sure if they will work or not. Can you change the ...apt-get install -y... to ...apt-get install -yqq...
Also, has that image changed that you're trying to build from?