Changes between Version 3 and Version 4 of Docker


Ignore:
Timestamp:
07/18/2025 06:00:02 PM (3 months ago)
Author:
Tim Harvey
Comment:

update instructions to use more simplistic --volume arg for bind mounts

Legend:

Unmodified
Added
Removed
Modified
  • Docker

    v3 v4  
    135135 - run container with a bind-mount from host {{{/usr/src/}}} to containers {{{/usr/src}}}
    136136{{{#!bash
    137 docker run -it --mount type=bind,source=/usr/src,target=/usr/src ubuntu-16.04
    138 }}}
    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.04
     137docker 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
     141docker run --privileged -it --volume /usr/src:/usr/src ubuntu-16.04
    142142}}}
    143143 - Notes:
     
    177177 - run container with a bind-mount from host {{{/usr/src/}}} to containers {{{/usr/src}}}
    178178{{{#!bash
    179 docker run -it --mount type=bind,source=/usr/src,target=/usr/src ubuntu-16.04
     179docker run -it --volume /usr/src:/usr/src ubuntu-16.04
    180180}}}
    181181 - create a volume and mount it in a container:
     
    198198
    199199This 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
     201The 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.
    200202
    2012031. Create a docker 'image' based on Ubuntu 20.04:
     
    224226
    225227# and set the prompt as a reminder
    226 RUN echo 'export PS1="\u@focal:\w\$ "' >> /home/$USER/.bashrc
     228RUN echo 'export PS1="\u@docker-focal:\w\$ "' >> /etc/bash.bashrc
    227229# switch to this user
    228230USER $USER
     
    230232EOF
    231233}}}
    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
     236docker build --tag ubuntu-22.04 --build-arg USER=$USER --build-arg UID=$(id -u) --build-arg GID=$(id -g) ubuntu-focal/
    235237}}}
    236238  * 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
     
    240242{{{#!bash
    241243docker 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 \
    244246  --name jammy ubuntu-jammy
    245247}}}
    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/src from the host OS to allow our host OS to get to source files we use
     248 * 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
    247249 * 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
    248250 * 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.