{"id":4341,"date":"2021-06-02T15:07:08","date_gmt":"2021-06-02T15:07:08","guid":{"rendered":"https:\/\/puvox.software\/blog\/?p=4341"},"modified":"2024-02-15T07:45:22","modified_gmt":"2024-02-15T07:45:22","slug":"useful-commands-for-docker-windows","status":"publish","type":"post","link":"https:\/\/puvox.software\/blog\/useful-commands-for-docker-windows\/","title":{"rendered":"Useful commands for docker (Windows)"},"content":{"rendered":"<div class=\"default-content-clss content_4341 type_post \">\r\n<p class=\"wp-block-paragraph\">Sometimes, novice users might need a few useful commands to deal with docker images.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"build-dockerfile\">Build Dockerfile<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Navigate terminal to the folder where is <strong>Dockerfile<\/strong> and execute build:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">docker build -t myImageName .<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">(additionally, you might add <code>-f Dockerfile<\/code> after myImageName)<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"how-to-open-terminal-bash\">How to open Terminal (bash)<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If you use Windows and you will need to enter bash (to install other extensions or do whatever you want in terminal), after running the container, you can enter there from cmd, using command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">Windows:\r\nFOR \/F \"tokens=*\" %g IN ('docker ps --filter \"ancestor=<strong>YOUR_IMAGE_NAME_HEREEEE<\/strong>\" -q') do (docker exec -ti %g bash)\r\n\r\nLinux:\r\ndocker exec -ti $(docker ps -aqf \"ancestor=<strong>YOUR_IMAGE_NAME_HEREEEE<\/strong>\") bash \r\n<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"mounting-custom-folder\">Mounting custom folder<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If you want to run it on custom port or want to mount your local folder as <code>www-root<\/code> (or even a separate plugin cases) for wordpress, then you can run the new container by:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">docker run -d -p 8080:80 -v \"D:\\\\your-folder\\\\\":\/var\/www\/html\/ -it wp-php8<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"connecting-to-local-mysql-server\">Connecting to local Mysql server<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">If you have a case, that you want to connect the docker WP to local mysql server (i.e. to <code>xamp<\/code>, <code>wampserver<\/code> or alike&#8230;) then enter mysql console and create &amp; grant privileges to new user:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">CREATE USER '<strong>myuser1<\/strong>'@'*' IDENTIFIED BY '<strong>myuser1<\/strong>';\r\nGRANT ALL PRIVILEGES ON *.* TO '<strong>myuser1<\/strong>'@'*';<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">and in docker WP installation, you should put database host as <code>192.168.1.xxx<\/code> (correct that with your network ip. Note, you might need to append the port too, i.e. <code>:3306<\/code> ).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">&nbsp;<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"commit-changes-from-container-into-image\">Commit changes from container into image<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Typically, when you restart docker, you will need to re-run the container from image, so all changes made into image will be lost. To avoid that, you can commit changes (made in running container) into the base-image:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">docker commit <strong>containerID imageName<\/strong>\r\n<em>(to find ID, type <code>docker ps<\/code> )<\/em><\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id=\"export-backup-full-image\">Export (Backup) full image<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><code>docker save <strong>myImageName<\/strong> -o savedFileName.tar<\/code><br \/><code>docker load -i savedFileName.tar<\/code><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">OR<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><code>docker export your_containerid -o <code>savedFileName<\/code>.tar<\/code><br \/><code>docker import <code><code>savedFileName<\/code><\/code>.tar newimagename:tagname<\/code><br \/>(check difference: <a href=\"https:\/\/stackoverflow.com\/questions\/22655867\/\">https:\/\/stackoverflow.com\/questions\/22655867\/<\/a> )<\/p>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<div class=\"default-content-clss excerpt_4341 type_post \"><p>Sometimes, novice users might need a few useful commands to deal with docker images. Build Dockerfile Navigate terminal to the folder where is Dockerfile and execute build: docker build -t<a class=\"excerpt-read-more\" href=\"https:\/\/puvox.software\/blog\/useful-commands-for-docker-windows\/\">(Continue Reading)<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17],"tags":[],"class_list":["post-4341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/comments?post=4341"}],"version-history":[{"count":1,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4341\/revisions"}],"predecessor-version":[{"id":5526,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4341\/revisions\/5526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media\/5523"}],"wp:attachment":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media?parent=4341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/categories?post=4341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/tags?post=4341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}