Your content here
In most situations, by default, you will be required to run docker commands using either the root user or by using the sudo
command. If you wish to avoid having to do this, you can add your user to the docker group by running usermod -aG docker user
. You will then need to restart your session in order to reload the permissions.
This applies to
docker
only.podman
is designed to work in rootless modes and thus increasing security
Most commands here have a 1-1 with
podman
, meaning that if you are runningpodman
rather thandocker
you can simply substitutedocker
forpodman
.
docker ps
This will give an output for the currently running containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b9e8e49409a ghcr.io/requarks/wiki:2 "docker-entrypoint.s…" 11 days ago Up 11 days 3443/tcp, 0.0.0.0:80->3000/tcp dockerfiles_wiki_1
1d8837d6f85e torotech "/bin/sh -c 'hugo se…" 11 days ago Up 11 days 0.0.0.0:41212->1313/tcp torotech
This gives you the following information
You can also see dead containers by executing
docker ps --all
docker exec -it docker_container /bin/bash
Once you are connected to the container, you can then run (in this case) BASH commands as expected and navigate the file system.
In order to dettach from the container press Ctrl + p then Ctrl + q
Ctrl + c will shut the container down
docker cp SOURCE_PATH DEST_PATH
This command will allow you to copy files to or from a running or stopped container.
To copy files to a container do docker cp somefile CONTAINER:/path/to/copy/to
To copy files from a container do docker cp CONTAINER:/path/to/somefile /host/path/to/copy/to
docker logs CONTAINER
This command will output the logs of the specified CONTAINER.
To view the most recent logs do docker logs shifty_blender
To follow the logs do docker logs -f shifty_blender
First you will need a system were you can pull/build a container image on, then save it and then copy to to the offline server.
docker pull <image-name>
docker save -o container.tar <image-name>
docker load -i container.tar
docker run [OPTIONS] <image-name>
Worked example:
Copying Wiki.js from online host to offline host
Online:
[user@online ~]$ docker pull ghcr.io/requarks/wiki
Trying to pull ghcr.io/requarks/wiki:latest...
Getting image source signatures
Copying blob 4f4fb700ef54 done |
Copying blob 31e352740f53 done |
Copying blob ddb7cc70f260 done |
Copying blob 2629b68d4311 done |
Copying blob 18afe6373474 done |
Copying blob 88ec59e3b80e done |
Copying blob 710fc81a2a82 done |
Copying blob 4e75fc591abd done |
Copying blob d11f75e9538b done |
Copying blob 37595d564d08 done |
Copying blob b6015734afb2 done |
Copying blob 6c63ee65d20b done |
Copying blob 2442912e7d55 done |
Copying config 58e34147fe done |
Writing manifest to image destination
58e34147fec57eab7c09a567f362b0ac0187398369f5e1c7298e7f2044e410d7
[user@online ~]$ docker save -o wikijs.tar wiki:latest
Copying blob 78a822fe2a2d done |
Copying blob 346a05841508 done |
Copying blob 9f5873e20035 done |
Copying blob 9f68b297c3a0 done |
Copying blob 20e2d8300446 done |
Copying blob 5f70bf18a086 done |
Copying blob f3b08c7e4fb8 done |
Copying blob faa00d79d52c done |
Copying blob 3ac843f6154e done |
Copying blob 2ef90e7f241e done |
Copying blob 0ed1e26d044f done |
Copying blob 8d1ddb18f3e7 done |
Copying blob 854a280ee479 done |
Copying config 58e34147fe done |
Writing manifest to image destination
Once copied to offline host:
[user@offline ~]$ docker load -i wikijs.tar
Getting image source signatures
Copying blob 6d8a1f90b5c3 done
Copying blob a2e4f7bc839d done
Copying blob 8741d6e90caf done
Copying blob b9f305a7d81e done
Copying blob 2c6f8b40a173 done
Copying blob d047f2e15a8b done
Copying blob f61a9e83c0b2 done
Copying blob 3e5b7a80d914 done
Copying blob 5a2f8e1b6d37 done
Copying blob c7f40b6d92a8 done
Copying blob e3a9d6b4c1f8 done
Copying blob 8b17f2d694c0 done
Copying blob 4f8e2a1b3c7d done
Copying config 1a9e83c0b2 done
Wring manifest to image destination
Loaded image: ghc.io/requarks/wiki:latest
[user@offline ~]$ docker run -d -p80:3000 --name wiki --restart unless-stopped -e "DB_TYPE=sqlite" -e "DB_FILEPATH=wikijs.sqlite" wiki:latest
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a
[user@offline ~]$
Command | Action |
---|---|
docker restart container_id |
Restarts the container "container_id". This can either be the "NAME" or the "CONTAINER ID" |