Where I can find all variables of docker image - docker

Where I can find variables or docker image after pulling - like for mongo image there are variables like MONGO_INITDB_ROOT_USERNAME but I have to find them on web resources. Is there some sort of command to show variables like --help or example yaml file or any file that has information about these variables?
or maybe at least printing whole dockerfile but with filled variables placeholders if they were set along the way...

I would use docker exec to get a shell inside the container and use printenv like below:
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a35281f615b1 adminer "entrypoint.sh docke…" 2 months ago Up 6 hours 0.0.0.0:8090->8080/tcp, :::8090->8080/tcp data-mock_adminer_1
016b075fee00 quay.io/keycloak/keycloak:latest "/opt/jboss/tools/do…" 2 months ago Up 5 seconds 8443/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp docker-scripts_keycloak_1
0409951e3c5f mysql:5.7 "docker-entrypoint.s…" 2 months ago Up 5 seconds 3306/tcp, 33060/tcp docker-scripts_mysql_1
❯ docker exec -it 016 /bin/bash
bash-4.4$ printenv
LAUNCH_JBOSS_IN_BACKGROUND=1
LANG=en_US.UTF-8
PROXY_ADDRESS_FORWARDING=false
HOSTNAME=016b075fee00
JDBC_MARIADB_VERSION=2.5.4
DB_USER=keycloak
container=oci
JDBC_POSTGRES_VERSION=42.2.5
DB_ADDR=mysql

#HenriDeBel's answer is fine but requires spinning a container (with docker run or so) from the image.
To avoid this (if the environment variables you are interested in have been added using ENV commands), note that you can just rely on docker inspect to list these environment variables.
For example, the following command (inspired by this answer by #VonC − How to get ENV variable when doing Docker Inspect) can be used to get them in a JSON format:
$ sudo docker inspect -f '{{json .Config.Env}}' coqorg/base:4.07.1-flambda
["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","OPAM_VERSION=2.0.8","NJOBS=2","OPAMPRECISETRACKING=1","COMPILER=4.07.1+flambda","OCAMLFIND_VERSION=1.8.1","DUNE_VERSION=2.8.5","ZARITH_VERSION=1.12"]

Related

Recover data for Postgress in Docker after docker-compose down

i have a problem.
First i needed to install Redis on my project, so i went to file docker-compose.xml , done some chenges in file and after that i use command docker-compose down , and docker-compose up. As result i don`t see data in my database postgres(( i looked all volumes in docker, and one of them has date 3 days ago, can i take this volume,i think it can be restore some data for me, but i dont know how to do it.
vadym#vadym-K56CM:~$ docker volume ls
DRIVER VOLUME NAME
local 7fd43398fb9942381adf3a866c9408ee3cbe24e5d33ed4e4374bfcea77405ed7
local 7fe3a58893af638ca2a7ac8389cc8794cd1ab56a807ce4b8ee47ed67b8d67b90
local 562d3c85b32450f0f8bfc73420438a72f7b6651317f7efa43cd38e6d9a7de887
local e698eb5804793b624159ae4e2eef01e15b43bd937e139aa586b0ec35b209c376
local linkup_redis
local vscode
i need to restore volume with name 562d3c85b32450f0f8bfc73420438a72f7b6651317f7efa43cd38e6d9a7de887.
My container
vadym#vadym-K56CM:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01f8d5219a62 redis "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:6379->6379/tcp redis
22eb79cb829e dpage/pgadmin4 "/entrypoint.sh" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp, 443/tcp postgres_gui
4e98b4c62cc4 postgres:14.4 "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:5432->5432/tcp postgres_container
Thanks!
You should be able to mount the volume to a new container and then copy data from it.
E.g. here is how to create a minimalistic container, mount the specified volume as read-only (see :ro at the end) and copy data from that volume into directory backup:
docker run -it -v <volumeID>:/mnt/myvolume:ro --name mycontainer alpine
docker cp mycontainer:/mnt/myvolume .\backup\

Why can container IDs be abbreviated in docker but not image tags, container names or image digests?

Given, on the repository I have a situation like this:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myrepo:5000/myimage latest 1c3c75da38df 3 days ago 546MB
myrepo:5000/myimage 20181130-CET183709 1c3c75da38df 3 days ago 546MB
myrepo:5000/myimage 20181126-CET191306 b143d325cd0e 7 days ago 846MB
myrepo:5000/myimage 20181122-CET190934 ccf40fb5ec0f 11 days ago 746MB
And a container running:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73d78cb7d34e myrepo:5000/myimage "uwsgi --plugin http…" 3 minutes ago Up 3 minutes 0.0.0.0:9090->8443/tcp heuristic_noyce
I can do:
docker exec -ti 73d7 bash --login # works - shortened container ID
but not:
docker exec -ti heuristic bash --login # fails - shortened container name
docker exec -ti heuristic_noyce bash --login # works - full container name
I can not pull a docker image by shortened digest like so:
docker pull myrepo:5000/myimage#sha256:b143d # fails - shortened image ID (digest)
Pulling a docker image by shortened tag also fails:
docker pull myrepo:5000/myimage:20181126 # fails - shortened tag
docker pull myrepo:5000/myimage:20181126-CET191306 # works - complete tag
Why not allow abbreviations for all of these?
Is there a workaround? I mean I'd understand it failing, when there were two or more tags starting with 20181126, but in cases where it is unambiguous? Where would I make a feature request for that?

Docker volume keeps exiting after starting

I'm following a Docker tutorial on Katacoda. But I am using my personal machine and not their interactive environment. All of the following commands work as expected in the Katacoda environment but not so much on my personal machine.
The aim of the tutorial is to learn how to persist data using volumes.
My directory looks like that following
docker-volumes
|_ data
The file data, is a file containing the text SET Key0 Value0
So I follow the instructions in the tutorial and I enter the following command:
docker run -v /docker/redis-data:/data --name r1 -d redis redis-server --appendonly yes
The output of the command is a hash.
When I enter docker ps the output shows that there is no container running. I thought the flag -d runs the container in the background?
If I enter docker ps -a I get this output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e1ca74b9bd7 redis "docker-entrypoint..." 4 minutes ago Exited (1) 4 minutes ago r1

moving docker-compose images between hosts

based on Moving docker-compose containersets
I have loaded the images :
$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
br/irc latest 3203cf074c6b 23 hours ago 377MB
openjdk 8u131-jdk-alpine a2a00e606b82 5 days ago 101MB
nginx 1.13.3-alpine ba60b24dbad5 4 months ago 15.5MB
but now i want to run them, as they would run with docker-compose, but i cannot find any example.
here is the docker-compose.yml
version: '3'
services:
irc:
build: irc
hostname: irc
image: br/irc:latest
command: |
-Djava.net.preferIPv4Stack=true
-Djava.net.preferIPv4Addresses
run-app
volumes:
- ./br/assets/br.properties:/opt/br/src/java/br.properties
nginx:
hostname: nginx
image: nginx:1.13.3-alpine
ports:
- "80:80"
links:
- irc:irc
volumes:
- ./nginx/assets/default.conf:/etc/nginx/conf.d/default.conf
so how can i run the container, and attach to it, to see if its running, and in what order do i run these three images. Just started with docker, so not sure of the typical workflow ( build, run, attach etc )
so even though i do have docker-compose yml file, but since i have the build images from another host, can i possibly run docker commands to run and execute the images ? making sure that the local images are being referenced, and not the ones from docker registry.
Thanks #tgogos, this does give me a general overview, but specifically i was looking for:
$ docker run -dit openjdk:8u131-jdk-alpine
then:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc6ceb8a82f8 openjdk:8u131-jdk-alpine "/bin/sh" 52 seconds ago Up 51 seconds vibrant_hodgkin
shows its running
2nd:
$ docker run -dit nginx:1.13.3-alpine
3437cf295f1c7f1c27bc27e46fd46f5649eda460fc839d2d6a2a1367f190cedc
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3437cf295f1c nginx:1.13.3-alpine "nginx -g 'daemon ..." 20 seconds ago Up 19 seconds 80/tcp vigilant_kare
cc6ceb8a82f8 openjdk:8u131-jdk-alpine "/bin/sh" 2 minutes ago Up 2 minutes vibrant_hodgkin
then: finally:
[ec2-user#ip-10-193-206-13 DOCKERLOCAL]$ docker run -dit br/irc
9f72d331beb8dc8ccccee3ff56156202eb548d0fb70c5b5b28629ccee6332bb0
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f72d331beb8 br/irc "/opt/irc/grailsw" 8 seconds ago Up 7 seconds 8080/tcp cocky_fermi
3437cf295f1c nginx:1.13.3-alpine "nginx -g 'daemon ..." 56 seconds ago Up 55 seconds 80/tcp vigilant_kare
cc6ceb8a82f8 openjdk:8u131-jdk-alpine "/bin/sh" 2 minutes ago Up 2 minutes vibrant_hodgkin
All three UP !!!!
Your question is about docker-compose but you also ask things about run, build, attach which makes me think I should try to help you with some basic information (which wasn't so easy for me to cope with a couple of months ago :-)
images
Images are somehow the base from which containers are created. Docker pulls images from http://hub.docker.com and stores them in your host to be used every time you create a new container. Changes in the container do not affect the base image.
To pull images from docker hub, use docker pull .... To build your own images start reading about Dockerfiles. A simple Dockerfile (in an abstract way) would look like this:
FROM ubuntu # base image
ADD my_super_web_app_files # adds files for your app
CMD run_my_app.sh # starts serving requests
To create the above image to your host, you use docker build ... and this is a very good way to build your images, because you know the steps taken to be created.
If this procedure takes long, you might consider later to store the image in a docker registry like http://hub.docker.com, so that you can pull it from any other machine easily. I had to do this, when dealing with ffmpeg on a Raspberry Pi (the compilation took hours, I needed to pull the already created image, not build it from scratch again in every Raspberry).
containers
Containers are based on images, you can have many different containers from the same image on the same host. docker run [image] creates a new container based on that image and starts it. Many people here start thinking containers are like mini-VMs. They are not!
Consider a container as a process. Every container has a CMD and when started, executes it. If this command finishes, or fails, the container stops, exits. A good example for this is nginx: go check the official Dockerfile, the command is:
CMD ["nginx"]
If you want to see the logs from the CMD, you can docker attach ... to your container. You can also docker stop ... a running container or docker start ... an already stopped one. You can "get inside" to type commands by:
docker exec -it [container_name] /bin/bash
This opens a new tty for you to type commands, while the CMD continues to run.
To read more about the above topics (I've only scratched the surface) I suggest you also read:
Is it possible to start a shell session in a running container (without ssh)
Docker - Enter Running Container with new TTY
How do you attach and detach from Docker's process?
Why docker container exits immediately
~jpetazzo: If you run SSHD in your Docker containers, you're doing it wrong!
docker-compose
After you feel comfortable with these, docker-compose will be your handy tool which will help you manipulate many containers with single line commands. For example:
docker compose up
Builds, (re)creates, starts, and attaches to containers for a service.
Unless they are already running, this command also starts any linked services.
The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running
To run your docker-compose file you would have to execute:
docker-compose up -d
Then to see if your containers are running you would have to run:
docker ps
This command will display all the running containers
Then you could run the exec command which will allow you to enter inside a running container:
docker-compose exec irc
More about docker-compose up here: https://docs.docker.com/compose/reference/up/

How to find what ports are exposed from docker image?

I have some docker image. In my example it is called sample_nginx:
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
sample_nginx latest 4b34f8307839 34 hours ago 231.6 MB
I can run it docker run sample_nginx and in the colomn "PORTS" I can see what ports are exposed from that image:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
650d7a9fe46e sample_nginx:latest "/bin/sh -c 'nginx - 3 minutes ago Up 3 minutes 80/tcp sleepy_mclean
Is it possible to find out what ports are exposed from the image without running it?
You can use docker inspect on an image to find this (and a variety of other interesting things):
$ docker inspect redis:latest
The above command will give you a significant amount of detail. You can alternately pass a format argument to return just what you're looking for, as below.
$ docker inspect --format='{{.Config.ExposedPorts}}' redis:latest
map[6379/tcp:map[]]

Resources