How to setup docker-machine to be as default? - docker

I want to rebuild everything from my docker VM named default, I used docker-compose down but it only removed the containers, all the requirements are still installed and I would like it to be as it was from the beginning so I can 're'-setup everything. Is it possible ?

This will remove all containers, images and volumes
docker rm -f $(docker ps -aq)
docker image rm $(docker image ls -q)
docker volume rm $(docker volume ls -q)
There are other things like networks and secrets that will not be removed, but they should not cause any problems.
If you are using a newer version of docker try the docker system prune -a command instead.
But maybe the --no-cache argumant ist the real solution for your problem. With it, docker will not use the cache and will do a full rebuild of the image.

The simple solution that will ignore previous builds:
docker-compose build --no-cache
But if you want something more destructive:
docker-machine rm default
docker-machine create default
eval $(docker-machine env default)

Related

Azerothcore - Docker .env MySQL-Password not working

This was orginally asked via this github issue:
https://github.com/azerothcore/azerothcore-wotlk/issues/3527
When copying the ./.env.dist file to ./.env and changing the password for the mysql database the password is still set to "password" after the containers are up and running.
Per the docker install guide here:
https://www.azerothcore.org/wiki/Install-with-Docker
Doing this should change the mysql database password.
I have tried the following:
docker rm $(docker ps -aq)
docker rmi $(docker images -q)
docker system prune
but still no luck. I've tried it with an older version of the repo from my backup and there it is working.
There is a persistent volume for the ac-database docker. here is what I would try:
docker-compose stop
docker-compose down
docker system prune
docker system prune --volumes

Unable to delete docker images

I'm newby in Devops culture and also eager to learn and use but I get stuck every time when i try something new and now i can't delete images.
It says; it's being used by running container, stop it and then.....
See the screenshots:
enter image description here
enter image description here
enter image description here
Get running containers
docker ps
Get all running and stopped container
docker ps -a
Stop single container
docker stop <container_id>
Stop all containers
docker stop $(docker ps -aq)
Remove single container
docker rm <container_id>
Remove all containers
docker rm $(docker ps -aq)
Remove single image
docker rmi <image_id>
Remove all images
docker rmi $(docker images -q)
Remove everything from Docker host machine(use with caution because will delete everything like images, containers,networks etc)
docker system prune
You can just force remove the image even when there is a container that is still using it, if you don't mind doing that.
docker image rm <image-name> --force
Best way to delete all stopped containers is
docker container prune
As for the running containers, you should be able to list them with
docker container ls
add (--all) to see all (running/stopped) containers
docker container ls --all
Use docker ps -a to list all your running containers. You will find the ones still running. Stop them by using docker stop NAMEOFTHECONTAINER and remove them with docker rm NAMEOFTHECONTAINER.

reset a docker container to its initial state every 24 hours

I need to reset a moodle docker to its initial state every 24 hours. This docker will be a running a demo site where users can login and carry out various setting changes and the site needs to reset itself every day. Does docker provide any such feature?
I searched for a docker reset command but it doesn't seem to be there yet.
Will such a process of removing and reinitiating docker container work?
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)
docker-compose up -d
I should be able to do this programatically ofcourse, preferably using a shell script.
Yes you do not need to reset just recreate the container is enough but if you bind volumes with the host it will not work if there is anything that pick from persistent storage of the host in docker-compose up.
Write a bash script that will run every 1:00 AM or whatever time you want to create fresh container.
0 0 * * * create_container.sh
create_container.sh
#!/bin/bash
docker-compose rm -f
docker-compose up -d
or you can use your own script as well but if there is bind volumes the clear that files before creating the container.
rm -rf /path/to_host_shared_volume
docker rm -f $(docker ps -a -q)
.
.
.
As the behavour of -v is different it will create directory if not exist.
Or if you want to remove everything then you can use system-prune
#!/bin/bash
docker system prune -f -a --volumes
docker-compose up -d
Remove all unused containers, networks, images (both dangling and unreferenced), and volumes.
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all images without at least one container associated to them
- all build cache

Remove multiple containers from docker from Windows cmd

I want to remove multiple containers at a time using windows cmd I have used docker rm | docker ps -a -q but not working. Anyone, please help me on this.
docker rm $ (docker ps -a -q) this is not working on windows.
it's removing only stopped containers. You first stop the containers and then remove them using your command or forcefully remove them, also, check this out, this thread, as well docker system prune
$ docker stop $(docker ps -a -q)
$ docker rm $ (docker ps -a -q)
Hope this works on Windows cmd as well.
Use Windows powershell to run this command docker rm $ (docker ps -a -q)

How to remove all docker volumes?

If I do a docker volume ls, my list of volumes is like this:
DRIVER VOLUME NAME
local 305eda2bfd9618266093921031e6e341cf3811f2ad2b75dd7af5376d037a566a
local 226197f60c92df08a7a5643f5e94b37947c56bdd4b532d4ee10d4cf21b27b319
...
...
local 209efa69f1679224ab6b2e7dc0d9ec204e3628a1635fa3410c44a4af3056c301
and I want to remove all of my volumes at once. How can I do it?
The official command to remove all unused data (including volumes without containers) will be with docker 1.13
docker system prune
If you want to limit to volumes alone, removing only unused volumes:
docker volume prune
You also have docker image prune, docker container prune, etc:
See more at "Prune unused Docker objects".
See commit 86de7c0 and PR 26108.
You can see it in action in play-with-docker.com:
/ # docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1296a5e47ef3 hello-world "/hello" 7 seconds ago Exited (0) 6 seconds ago prickly_poincare
/ # docker system prune
WARNING! This will remove:
- all stopped containers
- all volumes not used by at least one container
- all networks not used by at least one container
- all dangling images
Are you sure you want to continue? [y/N] y
Deleted Containers:
1296a5e47ef3ab021458c92ad711ad03c7f19dc52f0e353f56f062201aa03a35
The current (pre-docker 1.13) way of managing volume was introduced with PR 14242 and the docker volume command, which documents in its comment from July 2015:
docker volume rm $(docker volume ls -q --filter dangling=true)
Edited on 2017:
This answer was given on Apr 16 '16 and now is outdated, and correct only for docker version prior to 1.13
please use the answer from #VonC, now it is marked as correct
To delete unused volumes you can use the built-in docker volume rm command. The rm command also deletes any directory in /var/lib/docker/volumes that is not a volume, so make sure you didn't put anything in there you want to save:
Command to List volumes, little bit right than yours:
$ docker volume ls -qf dangling=true
Cleanup:
$ docker volume rm $(docker volume ls -qf dangling=true)
more details about ls here, about rm here
This is what I've found to be useful: https://github.com/chadoe/docker-cleanup-volumes
Shellscript to delete orphaned docker volumes in /var/lib/docker/volumes and /var/lib/docker/vfs/dir
Docker version 1.4.1 up to 1.11.x
It basically does a cleanup of any orphaned/dangling volumes, but it includes a --dry-run but it makes note of some docker included commands as well (which are referenced in prev comment)
Note about Docker 1.9 and up
To delete orphaned volumes in Docker 1.9 and up you can also use the built-in docker volume commands instead of this docker-cleanup-volumes script. The built-in command also deletes any directory in /var/lib/docker/volumes that is not a volume so make sure you didn't put anything in there you want to save:
List:
$ docker volume ls -qf dangling=true
Cleanup:
$ docker volume rm $(docker volume ls -qf dangling=true)
Or, handling a no-op better but Linux specific:
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
To answer the question and borrowing from Marc, this works:
$ docker volume rm $(docker volume ls -qf dangling=true | xargs)

Resources