Docker run new container (without Dockerfile)

1.1 Run docker to make a mariadb container on windows no password

docker run -d -it -p 3306:3306 -v C:/Users/username/Projects/projectname:/var/lib/mysql --name hostingnamedbs -e MYSQL_ALLOW_EMPTY_PASSWORD=1 --restart unless-stopped mariadb:10.11
docker run --name myhostingercouk -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -p 8000:80 -p 3306:3306 -v //c/Users/username/Projects/projectname:/var/lib/mysql -d mariadb:10.11

1.2 Run docker to make a mariadb container on windows with password

docker run -d -it -p 3306:3306 -v C:/Users/imran/Projects/hostingname/db:/var/lib/mysql --name hostingnamedbs -e MYSQL_ROOT_PASSWORD=strongrootpassword --restart unless-stopped mariadb:10.11

2. Run docker bash in server mode for latest ubuntu image, with port proxying external 80 to internal 3128, under name myhub, passing through external folder /home/imran

docker run -d -t -p 81:3128 -v /home/imran/Projects:/home --name mycontainer ubuntu:latest /bin/bash

Output:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
eea3ed22b802        ubuntu:latest       "/bin/bash"         6 seconds ago       Up 5 seconds        0.0.0.0:81->3128/tcp   mycontainer

2. Execute /bin/bash inside mydocker and get access to it. Inside container under /home will be all files from external /home/imran/Projects folder

imran@VDLAPTOP017:~$ docker exec -ti mycontainer /bin/bash
root@eea3ed22b802:/# cd /home

3. Stop mycontainer container

docker stop mycontainer

4. Next time to start mycontainer simply type

docker start mycontainer

5. Create new image ubuntu:mycontainer and save changes done in mycontainer into ubuntu:myubuntu

docker commit mycontainer ubuntu:myubuntu

6. It is possible now to recreate mycontainer based on ubuntu:myubuntu image

docker rm mycontainer
docker run -d -t -p 81:3128 -v /home/imran/Projects:/home --name mycontainer ubuntu:myubuntu /bin/bash

Leave a Reply