Docker Config Reference (docker create)

We go over many examples of the docker create examples!

Docker Config Reference (docker create)
docker create example guide 

Example 1

docker create --name simplecont nginx:latest

This command creates a new container named "simplecont" from the "nginx:latest" image without starting it, allowing for subsequent configuration or inspection prior to execution, which is suitable for preparatory staging in deployment pipelines.

Example 2

docker create -it --name interactive ubuntu:24.04 /bin/bash

This command creates an interactive container "interactive" from "ubuntu:24.04" with a bash shell as the command, allocating a pseudo-TTY (-it) for later attachment, ideal for debugging or manual exploration sessions.

Example 3

docker create --name dbcont -e MYSQL_ROOT_PASSWORD=secret mysql:8.0

This command creates a container "dbcont" from "mysql:8.0", setting an environment variable for the root password, facilitating secure database setup without immediate startup.

Example 4

docker create --name webcont -p 8080:80 nginx:latest

This command creates "webcont" from "nginx:latest", mapping host port 8080 to container port 80, preparing for web service exposure upon starting.

Example 5

docker create --name datavol -v /host/data:/container/data busybox

This command creates "datavol" from "busybox", mounting a host directory "/host/data" to "/container/data" inside the container, enabling data persistence across container lifecycles.

Example 6

docker create --name reslimited --memory=512m --cpus=1.0 alpine

This command creates "reslimited" from "alpine", constraining memory to 512 MB and CPUs to 1.0, which is useful for resource-controlled testing environments.

Example 7

docker create --name netcustom --network mynet alpine

This command creates "netcustom" from "alpine", attaching it to a custom network "mynet", supporting isolated networking setups.

Example 8

docker create --name hostnet --network host busybox

This command creates "hostnet" from "busybox" using the host network mode, sharing the host's network stack for direct access to host interfaces.

Example 9

docker create --name nonet --network none ubuntu

This command creates "nonet" from "ubuntu" with no network isolation, preventing any network connectivity for security-sensitive workloads.

Example 10

docker create --name privilegedcont --privileged alpine

This command creates "privilegedcont" from "alpine" in privileged mode, granting extended capabilities like device access, suitable for system-level tasks.

Example 11

docker create --name usercustom --user 1000:1000 busybox

This command creates "usercustom" from "busybox" running as user/group ID 1000:1000, enhancing security by avoiding root privileges.

Example 12

docker create --name workdir --workdir /app node:20

This command creates "workdir" from "node:20", setting the working directory to "/app", standardizing file paths for application consistency.

Example 13

docker create --name entrycustom --entrypoint /bin/sh alpine

This command creates "entrycustom" from "alpine", overriding the entrypoint to "/bin/sh", allowing custom startup behaviors.

Example 14

docker create --name labelcont --label com.example.env=dev nginx

This command creates "labelcont" from "nginx" with a label "com.example.env=dev", facilitating metadata for filtering or orchestration.

Example 15

docker create --name healthcont --health-cmd "curl -f http://localhost" nginx

This command creates "healthcont" from "nginx" with a health check command, enabling automatic health monitoring upon starting.

Example 16

docker create --name restartpolicy --restart always alpine

This command creates "restartpolicy" from "alpine" with an "always" restart policy, ensuring automatic restarts on failure or host reboot.

Example 17

docker create --name ipcshare --ipc host busybox

This command creates "ipcshare" from "busybox" sharing the host's IPC namespace, allowing inter-process communication with host processes.

Example 18

docker create --name pidshare --pid host ubuntu

This command creates "pidshare" from "ubuntu" sharing the host's PID namespace, permitting visibility of host processes from within the container.

Example 19

docker create --name utsshare --uts host alpine

This command creates "utsshare" from "alpine" sharing the host's UTS namespace, synchronizing hostname and domainname with the host.

Example 20

docker create --name capadd --cap-add SYS_ADMIN busybox

This command creates "capadd" from "busybox", adding the SYS_ADMIN capability, granting administrative privileges for specific operations.

Example 21

docker create --name capdrop --cap-drop ALL ubuntu

This command creates "capdrop" from "ubuntu", dropping all capabilities, minimizing privileges for enhanced security.

Example 22

docker create --name deviceadd --device /dev/sda:/dev/xvda alpine

This command creates "deviceadd" from "alpine", mapping the host device "/dev/sda" to "/dev/xvda" inside, for hardware access.

Example 23

docker create --name tmpfsmount --tmpfs /tmp:size=64m busybox

This command creates "tmpfsmount" from "busybox" with a tmpfs mount at "/tmp" sized 64 MB, providing in-memory storage.

Example 24

docker create --name ulimitset --ulimit nofile=1024:1024 nginx

This command creates "ulimitset" from "nginx", setting file descriptor limits to 1024, controlling resource usage.

Example 25

docker create --name sysctlset --sysctl net.ipv4.ip_forward=1 alpine

This command creates "sysctlset" from "alpine", setting a sysctl parameter for IP forwarding, configuring kernel behaviors.

Example 26

docker create --name seccomp --security-opt seccomp=unconfined busybox

This command creates "seccomp" from "busybox" with unconfined seccomp profile, relaxing system call filters for compatibility.

Example 27

docker create --name apparmor --security-opt apparmor=unconfined ubuntu

This command creates "apparmor" from "ubuntu" with unconfined AppArmor profile, disabling mandatory access controls.

Example 28

docker create --name linkcont --link dbcont:db nginx

This command creates "linkcont" from "nginx", linking to "dbcont" as "db", enabling legacy service discovery via environment variables.

Example 29

docker create --name addhost --add-host internal:192.168.1.100 alpine

This command creates "addhost" from "alpine", adding a hosts entry for "internal" resolving to 192.168.1.100, for custom DNS resolution.

Example 30

docker create --name publishall -P nginx

This command creates "publishall" from "nginx", publishing all exposed ports to random host ports (-P), simplifying dynamic port mapping.