I dont know if it's possible to create a DockerFile from an existing private repository. I created a container and installed an configured the server (i dont remember all the commands), so now I want it to be syncronized with my GitHub account so whenever I push in the branch it updates the changes in the image as well.
For the automatic builds it says that I need a DockerFile but I never created one. Is there an option to automatically create a dockerfile from an exisitng image/container. Using the docker history command doesnt help much because I made the server configurations using docker exec.
Is it possible?
Thanks in advance.
I'm not sure if I get the exact question but here an example for multi stage docker build (build is dockerized itself) + a temp dependency stage (better layer cleanup) for a typescript example based on existing node.js images.
FROM node:12 AS build # this could be ANY base image you want.
WORKDIR /app
COPY package*.json .npmrc ./
RUN npm i
COPY . .
RUN npm run build
FROM node:12 AS deps
WORKDIR /app
COPY .npmrc .
COPY package*.json ./
RUN npm install --only=production
FROM node:12-alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY --from=deps /app/node_modules/ ./node_modules/
COPY --from=build /app/package.json .
COPY --from=build /app/build/src/ ./
COPY --from=build /app/build/config/ ./config/
CMD [ "node", "app.js" ]
You need to start over. Docker doesn't remember the commands you ran inside the container either, so it has no way to reconstruct the Dockerfile. In any case, running docker build
will always start from a clean environment, so it's helpful to build your Dockerfile without a bunch of manual installations.
For most languages you can probably easily find a sample Dockerfile by just looking for one. Most of these are a pretty generic form: start FROM
an appropriate base image, install OS dependencies, install library dependencies, COPY
the application in, build it, and set runtime metadata like CMD
. You might be able to use one unmodified for popular platforms, since it's a little unusual to mention specific files other than the one that lists your dependencies (Node's package.json
, Python's requirements.txt
, ...).
You can also build up a Dockerfile by hand fairly easily. Your secret weapon here is Docker layer caching: if you re-run docker build
and nothing has changed up to and including the current line, Docker will skip over it and use the result from the last build. You can fairly easily docker system prune
to get rid of the extra images that got creating during the building process. So a more incremental process can look like:
FROM
an appropriate base image RUN
line and re-run docker build
; do not docker exec
or try to modify things in placeRUN
line and re-run docker build
RUN ls -lrt
; or docker build
prints out 12-digit hex image IDs as it goes along, so docker run --rm -it 0123456789ab /bin/sh
to get a shell to poke around the result of a given stepDockerfile
to source controlThis is probably very similar to the process you did already, except instead of docker exec
ing a series of commands, you're writing them down in the Dockerfile
and building images.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.