Docker container – Run a container with access to the host’s docker daemon and volumes


docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes --mount source=myvol1,target=/vol alpine sh

 

The above command runs a container (alpine image). Inside this container, you have access to the docker daemon of the host as well as the volumes.

Meaning that, from that container, you can manage containers (start, stop, inspect, …)

You can also start new containers with volumes.


apk update && apk add docker

docker run --rm -it --mount source=myvol1,target=/vol alpine sh

 

Advertisements

Netdata in Docker – Monitor my machine

Netdata: https://github.com/netdata/netdata & https://www.netdata.cloud/

is a wonderful tool to monitor a device and trigger alarms

To run it in a second on your local machine, use this docker command

docker run -d --name=netdata -p 19999:19999 -v /proc:/host/proc:ro -v /sys:/host/sys:ro -v /var/run/docker.sock:/var/run/docker.sock:ro --rm --cap-add SYS_PTRACE --security-opt apparmor=unconfined netdata/netdata

Then access the dashboard http://localhost:19999

Docker – boot2docker -Share folder

To share another folder than the default one (C:\Users)

First, add the folder to share in VirtualBox

boot2docker-share-drive

Than, connect to the docker VM by running

docker-machine ssh

There you need to run

sudo mkdir --parents //d/tangu
sudo mount -t vboxsf tangu //d/tangu

The first command create the folder where the shared drive will be mounted and the second command actually mount the shared drive.

Of course you’ll need to adapt the paths I used here to match yours.
Note that the mount command takes as arguments

  • -t specifies the filesystem. Here its the one from virtualbox
  • tangu is the named of the shared folder defined in virtual box
  • //d/tangu is the destination of the mount shared drive that was created by the first command

You don’t want to type those commands everytime

Add those lines between the step STEP=”Checking status on $VM” and the step STEP=”Setting env” :

STEP="Mounting web directory"
"${DOCKER_MACHINE}" ssh default 'sudo mkdir --parents //d/tangu'
"${DOCKER_MACHINE}" ssh default 'sudo mount -t vboxsf tangu //d/tangu'

To the file start.sh located where you installed Docker Toolbox

Now everytime you will start boot2docker, it will auto mount this shared folder.

Credits : https://github.com/docker/machine/issues/1814#issuecomment-239957893

 

Docker – boot2docker – Create a new docker virtual machine to a specific location

Yesterday I told about moving the exisitng default boot2docker machine to my secondary hard drive.

Today, I wanted to create a new docker virtual machine directly to a specific location.

docker-machine -s "D:\softwares\Docker Toolbox\docker-vm" create --driver virtualbox machineName

Set as default location

Finally, I want to always use this new location so as mentionned here I created the variable environnement MACHINE_STORAGE_PATH with the path = D:\softwares\Docker Toolbox\docker-vm