Changes between Version 3 and Version 4 of Docker
- Timestamp:
- 07/18/2025 06:00:02 PM (3 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Docker
v3 v4 135 135 - run container with a bind-mount from host {{{/usr/src/}}} to containers {{{/usr/src}}} 136 136 {{{#!bash 137 docker run -it -- mount type=bind,source=/usr/src,target=/usr/src ubuntu-16.04138 }}} 139 - run container in privileged mode (necessary to perform some root-specific functions like 'mount'within the container)140 {{{#!bash 141 docker run --privileged -it -- mount type=bind,source=/usr/src,target=/usr/src ubuntu-16.04137 docker run -it --volume /usr/src:/usr/src ubuntu-16.04 138 }}} 139 - run container in privileged mode (necessary to access host devices within the container) 140 {{{#!bash 141 docker run --privileged -it --volume /usr/src:/usr/src ubuntu-16.04 142 142 }}} 143 143 - Notes: … … 177 177 - run container with a bind-mount from host {{{/usr/src/}}} to containers {{{/usr/src}}} 178 178 {{{#!bash 179 docker run -it -- mount type=bind,source=/usr/src,target=/usr/src ubuntu-16.04179 docker run -it --volume /usr/src:/usr/src ubuntu-16.04 180 180 }}} 181 181 - create a volume and mount it in a container: … … 198 198 199 199 This example shows how to create an Ubuntu 20.04 Focal container from an Ubuntu host OS. The steps will vary a bit on other host Operating Systems. 200 201 The example here creates a local user with sudo access using variables (USER, UID, GID) that can be specified when you build the image to make it easier to share files on your host when using a bind mount. 200 202 201 203 1. Create a docker 'image' based on Ubuntu 20.04: … … 224 226 225 227 # and set the prompt as a reminder 226 RUN echo 'export PS1="\u@ focal:\w\$ "' >> /home/$USER/.bashrc228 RUN echo 'export PS1="\u@docker-focal:\w\$ "' >> /etc/bash.bashrc 227 229 # switch to this user 228 230 USER $USER … … 230 232 EOF 231 233 }}} 232 - use the 'docker build' command to build the OS image :233 {{{#!bash 234 docker build --tag ubuntu-22.04 --build-arg USER=$USER --build-arg UID=$(id -u) --build-arg GID=$(id -g) ubuntu- jammy/234 - use the 'docker build' command to build the OS image passing in args for your USER, UID, GID 235 {{{#!bash 236 docker build --tag ubuntu-22.04 --build-arg USER=$USER --build-arg UID=$(id -u) --build-arg GID=$(id -g) ubuntu-focal/ 235 237 }}} 236 238 * the '--build-arg' options above are optional but show how you can use your host Linux OS user/group to replace the default ones specified in the DockerFile. This can be very useful if you mount a filesystem from your host OS into your container and want to share user permissions … … 240 242 {{{#!bash 241 243 docker run -it --privileged \ 242 -- mount type=bind,source=/usr/src,target=/usr/src\243 -- mount type=bind,source=/tftpboot,target=/tftpboot \244 --volume /home/$USER:/home/$USER \ 245 --volume /tftpboot/tftpboot \ 244 246 --name jammy ubuntu-jammy 245 247 }}} 246 * the '-- mount' options are optional but show how you can mount directories from your host OS to the container's OS. In this case we have mounted /tftpboot so we can copy files from the container to the hosts's tftpboot directory where a TFTP server may be running. We also mount /usr/srcfrom the host OS to allow our host OS to get to source files we use248 * the '--volume' options are optional but show how you can bind mount directories from your host OS to the container's OS. In this case we have mounted /tftpboot so we can copy files from the container to the hosts's tftpboot directory where a TFTP server may be running. We also mount your home director from the host OS to allow our host OS to get to source files we use 247 249 * Note that once you 'run' a container it remains present even if you have detached from it meaning you can later re-attach to it 248 250 * The '--it' option is a shortcut for '--interactive' and '--tty' which allocates a pseudo-TTY terminal and keeps STDIN open even if not attached. These options allow the bash process to start in the container, attaches the host OS console to the processes standard input/output/error, and allocates a text-only console.
