How to create a docker basic image


How to create a basic docker image

I use openSUSE15.2, and Docker to do operation this article describes.
The operation described in this article is in opensuse15 2 + docker environment.
To be simple, let us try to make my own system to be a Docker image.
Let’s be simple and try to make my own system into a docker image.

Edit /etc/fstab

If your system has only a single partition mounted on /, you do not have to do this step.
If your system has only one root partition, you do not need to perform this step.
If you have a lot of partiton, for example one for /boot, one for /usr, you need to delete them from your /etc/fstab, because in a docker image, there is no other partitions.
If you have multiple partitions, / boot and / usr, you need to delete them from / etc / fstab, because there are no multiple partitions in the docker image.
First, backup your /etc/fstab to an other place, then delete all lines.
First, back up / etc / fstab to a location, and then delete all rows.

tar your / filesystem

Move to /, execute a ‘tar’ command:
Enter the / directory and execute a tar command:

cd /
tar --one-file-system --exclude=ABCD.tar -c -f ABCD.tar .
  • –one-file-system
    Stay in local file system when creating archive.
  • –exclude=ABCD.tar
    exclude ABCD.tar.
    No ABCD Put tar into ABCD Tarry.

then restore your /etc/fstab file.
Then recover the / etc / fstab file.

Build the Docker image

At /, write a Dockerfile:

FROM scratch
ADD ABCD.tar /
  • FROM scracth
    build this image base on the most original image of Docker – scratch.
    The component is mirrored on scratch, the original image of docker.
    ‘scratch’ is a image with empty filesystem.
    ‘scratch ‘is a mirror with an empty file system.
  • ADD ABCD.tar /
    ‘ADD’ command will extract ABCD.tar, and copy them to / path of the image.
    The ‘Add’ command decompresses ABCD Tar, copy the file to the / directory of the image.
    Don’t use CMD, because CMD will not extract ABCD.tar .
    Do not use CMD command. CMD command will not decompress ABCD tar .

then execute ‘docker build’:

docker build -t MyFirstImage:1 .

use ‘docker images’ to see whether you have get this new image:

docker images

run this new image

docker exec -it MyFirstImage:1 bash 

Recommended Today

Vue2 technology finishing 3 – Advanced chapter – update completed

3. Advanced chapter preface Links to basic chapters: Link to component development: 3.1. Custom events of components 3.1.1. Binding custom events There are two implementation methods here: one is to use v-on with vuecomponent$ Emit implementation [PS: this method is a little similar to passing from child to parent]; The other is to use ref […]