Docker Config Reference (docker import)
We go over many examples of using the docker import guide!
Example 1
docker import container_export.tar myimportedimage:latest
This command imports the tar archive "container_export.tar" (typically from a docker export) as a new image tagged "myimportedimage:latest", creating a flat image without layers for simple filesystem-based deployments.
Example 2
docker import --change 'CMD ["/bin/sh"]' rootfs.tar shellimage:1.0
This command imports "rootfs.tar" as "shellimage:1.0" while applying a CHANGE directive to set the default command to "/bin/sh", customizing runtime behavior for interactive shell environments.
Example 3
docker import http://example.com/rootfs.tar remoteimage:latest
This command imports a tar archive from the remote URL "http://example.com/rootfs.tar" as "remoteimage:latest", enabling image creation from online sources without local downloads.
Example 4
cat local.tar | docker import - pipedimage:dev
This command imports from standard input (piped from cat "local.tar") as "pipedimage:dev", facilitating scripted or chained operations where files are generated dynamically.
Example 5
docker import --message "Imported from backup" backup.tar restored:stable
This command imports "backup.tar" as "restored:stable" with a commit message, documenting the image's origin for version control or auditing purposes.
Example 6
docker import --change 'ENTRYPOINT ["/app/entry.sh"]' appfs.tar entryimage:1.2
This command imports "appfs.tar" as "entryimage:1.2", modifying the entrypoint to "/app/entry.sh" for application-specific startup logic.
Example 7
docker import --platform linux/arm64 armrootfs.tar armimage:latest
This command imports "armrootfs.tar" as "armimage:latest" targeting the linux/arm64 platform, ensuring compatibility for ARM-based architectures.
Example 8
docker import --change 'EXPOSE 80' webroot.tar webimage:http
This command imports "webroot.tar" as "webimage:http", adding an EXPOSE directive for port 80 to document networking intentions.
Example 9
docker import --change 'ENV APP_ENV=production' envtar.tar prodimage:env
This command imports "envtar.tar" as "prodimage:env", setting an environment variable for production configurations.
Example 10
docker import https://secure.example.com/secure.tar secureimage:latest
This command imports from a secure HTTPS URL "https://secure.example.com/secure.tar" as "secureimage:latest", supporting encrypted transfers for sensitive filesystems.
Example 11
docker import --message "Test import" --change 'LABEL version=1.0' test.tar labeled:1.0
This command imports "test.tar" as "labeled:1.0", adding a message and label for metadata, enhancing image organization.
Example 12
echo -n "minimal content" | docker import - minimalimage:test
This command imports minimal content from stdin as "minimalimage:test", demonstrating creation of tiny images for testing.
Example 13
docker import --change 'USER appuser' userfs.tar nonroot:secure
This command imports "userfs.tar" as "nonroot:secure", changing the default user to "appuser" for security hardening.
Example 14
docker import --platform linux/amd64 amdrootfs.tar amdimage:latest
This command imports "amdrootfs.tar" as "amdimage:latest" for linux/amd64, targeting x86 architectures.
Example 15
docker import --change 'VOLUME /data' datatar.tar volimage:persistent
This command imports "datatar.tar" as "volimage:persistent", declaring a volume at "/data" for data persistence.
Example 16
docker import http://example.com/compressed.tar.gz | gunzip | docker import - decompressed:latest
This command chains imports from a compressed remote tar, decompressing inline to create "decompressed:latest".
Example 17
docker import --change 'WORKDIR /app' worktar.tar appdir:setup
This command imports "worktar.tar" as "appdir:setup", setting the working directory to "/app" for path consistency.
Example 18
docker import --message "Imported from legacy system" legacy.tar legacyimage:migrated
This command imports "legacy.tar" as "legacyimage:migrated" with a message, documenting migrations from older systems.
Example 19
docker import --platform windows/amd64 winrootfs.tar winimage:windows
This command imports "winrootfs.tar" as "winimage:windows" for Windows AMD64, supporting Windows containers.
Example 20
docker import --change 'CMD ["node", "server.js"]' nodetar.tar nodeapp:run
This command imports "nodetar.tar" as "nodeapp:run", setting a Node.js command for application execution.
Example 21
curl http://example.com/tarfile.tar | docker import - curledimage:latest
This command imports directly from a curl-fetched remote tar as "curledimage:latest", for network-based creations.
Example 22
docker import --change 'LABEL maintainer="admin@example.com"' maint.tar maintained:info
This command imports "maint.tar" as "maintained:info", adding a maintainer label for ownership documentation.
Example 23
docker import --platform linux/riscv64 riscvtar.tar riscvimage:experimental
This command imports "riscvtar.tar" as "riscvimage:experimental" for RISC-V architecture, targeting emerging hardware.
Example 24
docker import --message "Security hardened" --change 'USER nobody' secure.tar hardened:secure
This command imports "secure.tar" as "hardened:secure", with a message and user change for security enhancements.
Example 25
docker import ftp://example.com/ftp.tar ftpimage:imported
This command imports from an FTP URL "ftp://example.com/ftp.tar" as "ftpimage:imported", supporting legacy protocols if enabled.
Example 26
docker import --change 'EXPOSE 443' secureweb.tar httpsimage:secure
This command imports "secureweb.tar" as "httpsimage:secure", exposing port 443 for secure web services.
Example 27
docker import --platform linux/s390x s390tar.tar mainframeimage:legacy
This command imports "s390tar.tar" as "mainframeimage:legacy" for IBM zSystems architecture.
Example 28
docker import --change 'ENV DEBUG=true' debugtar.tar debugmode:enabled
This command imports "debugtar.tar" as "debugmode:enabled", setting a debug environment variable.
Example 29
docker import --message "From compressed archive" | gunzip < compressed.tar.gz | docker import - decompressed:msg
This command chains decompression and import with a message for "decompressed:msg".
Example 30
docker import --change 'VOLUME /logs' logtar.tar logged:persistent
This command imports "logtar.tar" as "logged:persistent", declaring a log volume for persistence.