I'm trying to load a Docker image into an environment without internet connection (nginx:stable-alpine).
Once I've downloaded the image with pull on a computer with internet connection, I use the save command:
docker image save --output docker-image-nginx.tar nginx:stable-alpine
Then I copy it to the environment without internet connection, and load it:
docker image load --input docker-image-nginx.tar
The image gets loaded and can be seen with docker image ls:
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx stable-alpine 8c1bfa967ebf 4 weeks ago 21.5MB
But when I create a container with the run command:
docker run --name nginx -p 8080:80 nginx:stable-alpine
I get this error:
/docker-entrypoint.sh: No files found in /docker-entrypoint.d/, skipping configuration
The container can be created with the same command on the computer with internet connection.
What's wrong in the process of saving and loading the image?
What about trying to save a docker container instead an image?
For example:
In your host with internet
docker run --name mynginx -p 8080:80 nginx:stable-alpine
docker save mynginx > mynginx.tar
In your host without internet
docker load < mynginx.tar
Related
Steps to reproduce:
Download and run postgres:9.6.24:
docker run --name my_container --restart=always -d -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=pgmypass postgres:9.6.24
Here result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
879883bfc84a postgres:9.6.24 "docker-entrypoint.s…" 26 seconds ago Up 25 seconds 127.0.0.1:5432->5432/tcp my_container
OK.
Open file inside container /var/lib/postgresql/data/pg_hba.conf
docker exec -it my_container bash
root#879883bfc84a:/# cat /var/lib/postgresql/data/pg_hba.conf
IPv4 local connections:
host all all 127.0.0.1/32 trust
Replace file /var/lib/postgresql/data/pg_hba.conf inside container by my file. Copy and overwrite my file from host to container:
tar --overwrite -c pg_hba.conf | docker exec -i my_container /bin/tar -C /var/lib/postgresql/data/ -x
Make sure the file has been modified. Go inside container and open changed file
docker exec -it my_container bash
root#879883bfc84a:/# cat /var/lib/postgresql/data/pg_hba.conf
IPv4 local connections:
host all all 0.0.0.0/0 trust
As you can see the content of file was changed.
Create new image from container
docker commit my_container
See result:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> ee57ad4bc6b4 3 seconds ago 200MB
postgres 9.6.24 027ccf656dc1 12 months ago 200MB
Now tag my new image
docker tag ee57ad4bc6b4 my_new_image:1.0.0
See reult:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my_new_image 1.0.0 ee57ad4bc6b4 About a minute ago 200MB
postgres 9.6.24 027ccf656dc1 12 months ago 200MB
OK.
Stop and delete old continer:
docker stop my_continer
docker rm my_container
See result:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
As you can see not exit any container. OK.
Create new continer from new image
docker run --name my_new_container_test --restart=always -d -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD=pg1210 my_new_image:1.0.0
See result:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a965dbbd991 my_new_image:1.0.0 "docker-entrypoint.s…" 7 seconds ago Up 6 seconds 127.0.0.1:5432->5432/tcp my_new_container
Open file inside container /var/lib/postgresql/data/pg_hba.conf
docker exec -it my_new_container bash
root#879883bfc84a:/# cat /var/lib/postgresql/data/pg_hba.conf
IPv4 local connections:
host all all 127.0.0.1/32 trust
As you can see my change in files are lost. The content of file is original. Not my changes.
P.S. This problem is only with file pg_hba.config. E.g if I created in the container the folder and file: /Downaloads/myfile.txt then this file not lost in the my container "my_new_container".
Editing files inside container with docker exec, in general, will in fact cause you to lose work. You mention docker commit but that's almost never a best practice. (If this was successful, but then you discovered PostgreSQL 9.6.24 exactly had some critical bug and you must upgrade, could you recreate the exact some image?)
In the case of the postgres image, the files in /var/lib/postgresql/data are always stored in a Docker volume or mount point. In your case you didn't use a docker run -v option, but the image is configured to create an anonymous volume in that directory. The volume is not included in docker commit, which is why you're not seeing it on the rebuilt container. (Also see docker postgres with initial data is not persisted over commits.)
For editing a configuration file, the easiest thing to do is to store the data on the host system. Create a directory to hold it, and extract the configuration file from the image. (Since the data directory is created by the image's startup script, you need a slightly longer path to get it out.)
mkdir pgdata
docker run -d --name pgtmp postgres:9.6.24
docker cp pgtmp:/var/lib/postgresql/data/pg_hba.conf ./pgdata
docker stop pgtmp
docker rm pgtmp
$EDITOR pgdata/pg_hba.conf
Now when you run the container, provide this data directory as a bind mount. That will inject the configuration file, but also cause the database data to persist over container exits.
docker run -v "$PWD/pgdata:/var/lib/postgresql/data" -u $(id -u) ... postgres:9.6.24
Note that this sequence doesn't use docker exec or "go inside" containers at all, and you haven't created an image without corresponding source. Everything is run with commands from the host. If you do need to reset the database data, in this setup, it's just files, and you can rm -rf pgdata, maybe saving the modified configuration file along the way.
(If I'm reading this configuration change correctly, you're trying to globally disable passwords and instead allow trust authentication for all inbound connections. That's not usually a good idea, especially since username/password authentication is standard in every database library I've encountered. You probably still want the volume to persist data, but I might not make this change to pg_hba.conf.)
Docker Container is a readyonly entity, which means if you will create a file into the container, remove it and re-create it (The container), the file is not supposed to be there.
what you want to do is one of two things,
Map your container to a local directory (volume)
Create a docker file based on the postgres image, and generate this modifications in a script, that your dockerfile reads.
docker volume usages
Dockerfile Reference
I have saved docker image and then load image.
$ sudo docker load -i e7bdb77cdcd8.tar
the images is loaded correctly
however i cannot start docker.
$ docker start e7bdb77cdcd8
Error response from daemon: No such container: e7bdb77cdcd8
Error: failed to start containers: e7bdb77cdcd8
docker start is used to start one or more stopped containers.
After you use docker load -i, it should load the artifact as a new docker image, you could see it using docker image ls.
Then, you should use docker run $your_loaded_image to run it.
I am new in docker and created a simple springboot hello world application. I created a dockerfile according to the tutorials and build it by docker.
FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} myapp-1.0.0.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-jar","/myapp-1.0.0.jar"]
EDIT: using -p gives another error which is Invalid or corrupt jarfile /myapp-1.0.0.jar
After that I tried to run the docker on my local machine. But I am getting an error which says unable to find image 8080:8080 locally.
docker run 8080:8080 --name myhelloimage myuser/myhelloimage:latest
I am able to see docker image by docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myuser/myhelloimage latest c5dfe18b0fb3 14 minutes ago 271MB
So what is wrong here why I am getting an error?
You didn't include the -p before 8080:8080, so the docker command is interpreting it as an image not a port mapping. You can see the full documentation here.
In my working environment , i can't connect to the network, but i can connect to the download machine ,which can connect to network .
But i do not know how to find a docker image and download it .
The website docker hub just show the command such as "docker pull nginx" , but i can't connect to the network ,it is useless for me .
My question:
Now, I have install docker by download docker-engine.deb.
where can I get a docker image off line?
You'll need access to a registry where docker images are stored. But if you don't have images and no registry with images yet, than you have to pull the image from the internet.
A recommended way could be:
Install docker on a machine (maybe your local machine) with internet access and pull an image:
$ docker pull busybox
Use docker save to make a .tar of your image
$ docker save busybox > busybox.tar
or you can use the following syntax
$ docker save --output busybox.tar busybox
Reference is here.
You can use a tool like scp to send the .tar to your Docker server where you don't have internet access.
Now you can use docker load to extract the .tar and get your image:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
$ docker load < busybox.tar.gz
Loaded image: busybox:latest
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 769b9341d937 7 weeks ago 2.489 MB
Reference is here
I have the following containers:
Data container which is build directly in quay.io from a github repo, basically is a website.
FPM container
NGINX container
The three of them are linked together and working just fine. BUT the problem is that every time I change something in the website (Data container) it is rebuilt (of course) and I have to remove that container and also the FPM and NGINX and recreate them all to be able to read the new content.
I started with a "backup approach" for what I'm copying the data from the container to a host directory and mounting that into the FPM and NGINX containers, this way I can update the data without restarting/removing any service.
But the idea of moving the data from the data container into the host, really doesn't like me. So wondering if there a "docker way" or a better way of doing it.
Thanks!
UPDATE: Adding more context
Dockerfile d`ata container definition
FROM debian
ADD data/* /home/mustela/
VOLUME /home/mustela/
Where data only has 2 files: hello.1 and hello.2
Compiling the image:
docker build -t="mustela/data" .
Running the data container:
docker run --name mustela-data mustela/data
Creating another container to link to the previous one:
docker run -d -it --name nginx --volumes-from mustela-data ubuntu bash
Listing the mounted files:
docker exec -it nginx ls /mustela/home
Result:
hello.1 hello.2
Now, lets rebuild the data container image, but first adding some new files, so now inside data we have hello.1 hello.2 hello.3 hello.4
docker rm mustela-data
docker build -t="mustela/data" .
docker run --name mustela-data mustela/data
If I ls /home/mustela from the running container, the files aren't being updated:
docker exec -it nginx ls /mustela/home
Result:
hello.1 hello.2
But if I run a new container I can see the files
docker run -it --name nginx2 --volumes-from mustela-data ubuntu ls /home/mustela
Result: hello.1 hello.2 hello.3 hello.4