Docker build error - docker

I'm trying to build a Docker image, and are following the basic tutorial on Dockers own page. My Dockerfile looks like
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
That is exact the same as Docker provide.
I'm running linux mint 18, and Docker is installed. I'm able to run images, like hello-world or others that I've build earlier and pushed to docker hub. (Used windows when i created them)
If I try to create images that I've created earlier, the same thing happens. It always crashes when RUN apt-get -y update && apt-get -y install.
Do anyone know how to solve this problem?
Thanks!
Picture of error message

As per the image it fails to resolve "archive.ubuntu.com"
do the following as per references.
Uncomment the following line in /etc/default/docker
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
Restart the Docker service sudo service docker restart
Delete any images which have cached the invalid DNS settings.
Build again and the problem should be solved.
Ref: Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything
Actual Ref: https://www.digitalocean.com/community/questions/docker-on-ubuntu-14-04-could-not-resolve-archive-ubuntu-com

Related

Yum update stucks inside docker

I have installed Docker 20.10 on RHEL 9 system, and installed CentOS 7 container on docker. But when I tried yum update on it, it takes a long time while running transaction, as if yum stuck while updating.
Yum update
I tried strace -p 6351 to see what is happening inside yum, and it endlessly says fnctl(765158398, F_GETFD) = -1 EBADF (Bad File Descriptor) strace -p 6351
Same thing happens when I tried yum install openssh-server, but yum install telnet worked fine.
I really want to know what is happening on my docker. Any idea to fix it??
After some research, I have found that ulimit -n, ulimit -Hn, ulimit -Sn value inside the container was 1073741824, and it made yum check every possible file descriptor, from 0 to 1073741824.
I have inserted --ulimit nofile=1024:262144 in docker commandline (like docker run --ulimit nofile=1024:262144 --name test -p 2202:22/tcp -i -t centos:7 /bin/bash), and yum update worked fine! Now I can enjoy yum on docker happily!
Is there also a solution without setting it in every docker container and maybe in containerd? I am experiencing similar issues in centos 7.9 containers running on centos 9 hosts using Kubernetes/containerd. Yum installations take hours instead of minutes.
Update: I've added LimitNOFILE=1048576 to the service unit of containerd now and it works.

How can I install docker on a VM using devcontainer.json?

I want to automate the installation of docker and docker-compose on a newly created VM. Ideally this should be done from the devcontainer.json file such that if a developer opens the project the Debian/Ubuntu packages docker.io and docker-compose are installed automatically.
I tried adding
"initializeCommand": "sudo apt update && sudo apt upgrade -y && sudo apt install -y docker.io docker-compose",
to the main hirarchy of devcontainer.json but it will not run before VS Code starts creating the container. VS Code gives an error message that Docker is not installed, although the initializeCommand command is supposed to be run before the container setup.
Is there any other way of achieving this except using additional tools or e.g. Azure VM templates?

Installing SSH on a Docker image

I'm trying to install SSH on a docker image using the command:
RUN APT INSTALL -Y SSH
This seemingly installs SSH on the image, however if I tunnel into a running container and run the command manually I get prompted to set both Region and Timezone. Is it possible to pass these options to the install SSH command?
The container I am able to manually install SSH on can be started with the command below:
docker container run -it --rm -p 22:22 ubuntu:latest
My Docker Image is as follows:
FROM ubuntu:latest
RUN apt update
apt -y install ssh
Thanks
You can use DEBIAN_FRONTEND to disable interaction with user (DEBIAN_FRONTEND):
noninteractive
This is the anti-frontend. It never interacts with you at all,
and makes the default answers be used for all questions. It
might mail error messages to root, but that's it; otherwise it
is completely silent and unobtrusive, a perfect frontend for
automatic installs. If you are using this front-end, and require
non-default answers to questions, you will need to preseed the
debconf database; see the section below on Unattended Package
Installation for more details.
Like this:
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/London
RUN apt update && \
apt -y install ...

Building a new container with mixed CMD and RUN command does not work

I am new in docker and I am learning how to build a new container. I faced an issue to build a container, inherited from Ubuntu. I want to install Python3 and some other packages on the Ubuntu container with proper messages, but it does not work.
When I build a container with Dockerfile with:
FROM ubuntu
CMD echo "hello new Ubuntu"
RUN apt-get upgrade && apt-get update && apt-get install -y python3
CMD echo "installed python"
the call of the built Ubuntu with docker run -it my_new_ubuntu does not enter to the interactive mode and it only prints installed python, not even the "hello new Ubuntu".
Although, when I build a container with Dockerfile without any message:
FROM ubuntu RUN apt-get upgrade && apt-get update && apt-get install
-y python3
and call the built container with docker run -it my_new_ubuntu, it enters the Ubuntu root and I can call python. I am not sure why the first Dockerfile does not work. It seems that I cannot mix RUN and CMD commands together.
I appreciate any help or comment.
RUN specifies a command to run while building an image from your Dockerfile. You can have multiple RUN instructions, and each will apply to the image in the order specified.
CMD specifies the default command the image has been instantiated into a container and started. If there are multiple CMD instructions, only the last one applies.

Docker-engine confilcts with docker.io

OS: Ubuntu 16.04
Docker version: 1.11.2
I have already installed docker 1.11.2 on my Ubuntu and I want to upgrade it to 1.12. All the steps are as follows:
I download the deb pkg named docker-engine_1.12.3-0~xenial_amd64.
Execute command: dpkg -i docker-engine_1.12.3-0~xenial_amd64 but notes with errors:
docker-engine conficts with docker.io.docker.io (version 1.11.2-0ubuntu5~16.04) has already been installed .
So I have to remove docker first by using commands as below:
service docker stop
apt-get remove docker
apt-get remove --auto-remove docker
rm -rf /var/lib/docker
Go to step 2, but with the same errors.
So, I hope someone would help me solve this problem.
The conflicting packages (which fight over the same binary) are docker.io (from the distribution) and docker-engine (from Docker itself).
Your command above does apt-get remove ... docker. Which achieve nothing for the aforementioned problem.
I have different machines running 16.04 and some use docker.io (easier, no extra repo) whereas others use docker-engine. I am indifferent. Pick on, docker should work just fine.
Firstly restart the ubuntu server with linux command(sudo shutdown -r now), and run the command : apt-get -f install(this command is suggested by the error information), then I install the docker-engine by the following site(https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04).

Resources