How to generate a Dockerfile from an image [duplicate] - docker

This question already has answers here:
How to generate a Dockerfile from an image?
(11 answers)
Closed 1 year ago.
One of our X employee has created an docker image. Currently i need to update the same image which was created by him. But unfortunately i couldn't find the Dockerfile for the image.
Is it possible to generate a dockerfile from an image?

this answer is good from here
This worked for me from the answers
docker pull chenzj/dfimage
alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm chenzj/dfimage"
dfimage image_id
you need the image id - not the name
e.g
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
so the third column.
There is still work to do with it and it all depends how the docker image was created

You can try running this command:
alias dfimage="docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage"
dfimage -sV=1.36 IMAGE_NAME:IMAGE_TAG
And note at Dockerfile

Related

docker in docker via bind mound - ubuntu

I need to have an ubuntu image and then run a build process using that image. All is well until the build gets to the point of doing docker build etc.
Lets say I use the following to test this:
Dockerfile
FROM ubuntu:latest
I then build that - docker build -t ubuntudkr .
Next, I run it like:
docker run -ti -v /var/run/docker.sock:/var/run/docker.sock ubuntudkr
When I then run docker ps inside this container, I get the error bash: docker: command not found
All the examples I've found says I need to run:
docker run -v /var/run/docker.sock:/var/run/docker.sock \
-ti docker
They all use the docker image which contains the docker library. Is my answer then to install docker inside my base image to make it work? Does this then not go against what docker themselves says?
There are many other blog posts out there that gave the same advice, but my example does work. Where do I go wrong?
Replace the image ubuntu:latest in your dockerfile by the official docker:latest image wich contains docker binaries and does exactly what you want: https://hub.docker.com/_/docker
If you want to keep the Ubuntu image, you must install Docker tools following your error. By default, the Ubuntu image does not contain Docker binaries as a regular Ubuntu installation.

NAMES column of "docker ps" output [duplicate]

This question already has answers here:
Container NAMES when deploying with Docker
(2 answers)
Closed 2 years ago.
Below is the docker file:
FROM golang:1.14.10
MAINTAINER xyz
ENV SOURCES /product-api
COPY . ${SOURCES}
WORKDIR /product-api
RUN make swagger
ENTRYPOINT product-api
After running the below commands:
$ docker build -t cloud-native-product-api:1.0.0
$ docker run -it -p 8080:8080 cloud-native-product-api:1.0.0
docker ps gives below output:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9aa144b7873c cloud-native-product-api:1.0.0 "/bin/sh -c product-…" 3 minutes ago Up 3 minutes 0.0.0.0:9090->9090/tcp trusting_matsumoto
Where does value trusting_matsumoto derive from in NAMES column?
Unless you specify a name for the container, docker assigns a random one.
You can specify a container name by using the --name argument:
$ docker run --rm -it --name my_alpine_container alpine
From the documentation
If you do not assign a container name with the --name option, then the daemon generates a random string name for you. Defining a name can be a handy way to add meaning to a container. If you specify a name, you can use it when referencing the container within a Docker network. This works for both background and foreground Docker containers.

How to derive "docker run" syntax from docker container [duplicate]

This question already has answers here:
How to show the run command of a docker container
(12 answers)
Closed 3 years ago.
I ran a docker run on a docker image with a long convoluted command syntax that I have since forgotton and lost. Is there any way to derive the syntax that ran a container given the container ID?
I know docker inspect can give you information about the container but I was hoping the docker run syntax would be saved somewhere.
As mentioned by Zeitounator, this was answered here, but just adding it here for completeness:
sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
assaflavie/runlike <Your_Container_ID>

How to build an image with a custom name?

When I build an image using docker build:
docker build .
I get an image with a random name.
How to create a docker image with a custom name?
I already know how to set the name in the Dockerfile, but I'm not sure how to use it in the build command.
You can use the -t flag, as shown in the documentation (or run docker build --help to learn about the options you have).
You should do:
docker build -t my-image .
Now the image is created with the name my-image:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-image latest 43070bef9dfa 2 minutes ago 464MB

How to show a dockerfile of image docker

I download a image from docker repository and Im trying to display the Dockerfile of 'X' image to create my own Dockerfile with the same structure to experiment with him. Im using this command:
docker inspect --format='{{.Config.Image}}' 'here paste the id of image'
That command return a 'sha256', some like this:
sha256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
but I need a command to display a json file with configuration of Dockerfile. Someone know how can I do this?
Sorry if the format or the question is not ok, Im a beginner!
Thanks everyone!
The raw output, as described in "How to generate a Dockerfile from an image?", would be:
docker history --no-trunc <IMAGE_ID>
But a more complete output would be from CenturyLinkLabs/dockerfile-from-image
docker run -v /var/run/docker.sock:/var/run/docker.sock \
centurylink/dockerfile-from-image <IMAGE_TAG_OR_ID>
Note there were limitations.
In 2020, as illustrated here:
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage \
-sV=1.36 <IMAGE_TAG_OR_ID>

Categories

Resources