Last active
September 8, 2019 09:29
-
-
Save inspiretk/6d77ec4dd5a398841c93a5c85e804cf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Youtube video here of the below instructions: https://youtu.be/WmN2Yc-75lE | |
############# START of File ############# | |
# Docker setup for Windows 7 64 bit. Need Docker Toolbox because Docker Windows uses Hyper V, and windows 7 dont have it. | |
# Docker Toolbox will install VirtualBox and you'll run docker containers inside your VirtualBox. | |
# You can bind your local machine Windows 7 folder to link it to your container inside your VirtualBox machine. | |
# Your windows 7 machine needs to be 64 bit, with virtualization. Full instructions here: https://docs.docker.com/toolbox/toolbox_install_windows/ | |
### Instructions ### | |
# 1. Install Docker Toolbox > Search for docker toolbox download and download it | |
# OR Download latest .exe file using this link https://github.com/docker/toolbox/releases | |
# eg https://github.com/docker/toolbox/releases/download/v19.03.1/DockerToolbox-19.03.1.exe | |
# Run the .exe file and install | |
# Change Environment Variables Path: add at end of line ;C:\Program Files\Docker Toolbox | |
# You'll get this error if you dont use the docker terminal eg if you use git bash and type | |
docker info | |
# You will get below error | |
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. | |
# To fix this, use the docker terminal. | |
# 2. Run Docker | |
# On your desktop > Double Click on Docker Quickstart Terminal | |
# > If error on bash, find the correct path of your git bin folder for bash.exe file location | |
# My git is installed in c:/programs, yours can be in c:/program files. Just find the Git folder > Go to Bin folder > Find bash.exe | |
# On your Desktop > Right Click Docker Quickstart Terminal > Properties > | |
Target: C:\Program\Git\bin\bash.exe --login -i "C:\Program Files\Docker Toolbox\start.sh" | |
# NOTE: your Git Bin folder could be different so find it on your machine | |
# 3. Using Docker | |
# In your Docker terminal: Type | |
# Top bar > Right Click > Properties > Options > Click Quick Edit Mode | |
# see info in your docker | |
docker info | |
docker-machine ip | |
docker container run -d -p 8080:80 --name mynginx nginx | |
# Go to your browser > Type in your docker ip:8080 > You'll see nginx page | |
docker container exec -it mynginx bash | |
cd /usr/share/nginx/html | |
exit | |
docker rm $(docker ps -aq) -f | |
# Go to your Users folder > c:/Users > Create folder docker > Go into docker folder > create folder nginx | |
# Note: Capital U for Users | |
docker container run -d -p 8080:80 -v /c/Users/docker/nginx:/usr/share/nginx/html --name mynginx nginx | |
# Go to your browser > Type in your docker ip:8080 > You'll see nginx page | |
# In docker terminal | |
cd c:/users/docker/nginx | |
# open up visual code in that folder [or do it manually in your code editor | |
code . | |
# create file index.html > put heading1 as Hello World 2 > Save file > Go to browser and refresh to see update | |
# create file about.html > put heading1 as About 2 > Save file > Go to browser > /about.html > See page about.html | |
#### Create Docker file | |
# create file Dockerfile > Put following code in | |
FROM nginx:latest | |
WORKDIR /usr/share/nginx/html | |
COPY . . | |
# In docker terminal | |
cd c:/users/docker/nginx | |
docker image build -t mynginxinit . | |
docker rm $(docker ps -aq) -f | |
docker container run -d -p 8080:80 --name mynginx mynginxinit | |
docker cp mynginx:/usr/share/nginx/html/ c:\\Users\\docker\\nginx2 | |
docker rm $(docker ps -aq) -f | |
docker container run -d -p 8080:80 -v /c/Users/docker/nginx2:/usr/share/nginx/html --name mynginx mynginxinit | |
cd c:/users/docker/nginx2 | |
code . | |
# In Visual Studio Code or your code editor, edit file index.html > put heading1 as Hello World 3 > Save file > Go to browser and refresh to see update | |
# In docker terminal | |
docker container exec -it mynginx bash | |
cd /usr/share/nginx/html | |
apt update | |
apt install nano | |
nano index.html | |
# Edit file index.html > put heading1 as Hello World 4 > Save file > Go to browser and refresh to see update | |
############# End of File ############# | |
##### Below are misc stuff not required but for information only ##### | |
apt update | |
apt install nano | |
nano index.html | |
# Put heading1 as Hello World > Save file > On your browser, refresh nginx page > You'll see it updated | |
docker rm $(docker ps -aq) -f | |
docker-machine url # see your docker ip | |
docker-machine ip default | |
docker images # see list of images thats on local machine | |
docker images --all | |
docker ps # see all container; or docker container ps | |
docker ps -a # shows all container even not running | |
docker container stop mysql # stop the container | |
docker container rm myapache # remove container | |
docker container rm myapache -f # forced removal if its running | |
docker container exec -it mynginx bash # tunnel into container | |
docker start mynginx # start up a container | |
docker rm $(docker ps -aq) -f # force remove all containers | |
List of docker commands: | |
https://gist.github.com/bradtraversy/89fad226dc058a41b596d586022a9bd3 | |
https://medium.com/@nagarwal/lifecycle-of-docker-container-d2da9f85959 | |
https://youtu.be/Kyx2PsuwomE?t=383 | |
Install Docker Toolbox. Go into folder, double click start.sh | |
fix shortcut to docker quickstatr | |
docker container run -it -p 80:80 nginx | |
* it means run in forground. p publish. first port in your local machine, 2nd exposed fm container | |
docker-machine env | |
docker container run -d -p 8080:80 --name mynginx nginx | |
docker container run -d -p 8081:80 --name myapache httpd | |
docker container run -d -p 3306:3306 --name mysql --env -- MYSQL_ROOT_PASSWORD=123456 mysql | |
docker container exec -it mynginx bash | |
winpty docker container exec -it mynginx bash # if on windows git bash admin winpty | |
https://www.jhipster.tech/tips/020_tip_using_docker_containers_as_localhost_on_mac_and_windows.html | |
changing docker ip to localhost | |
docker-machine stop default | |
Open VirtualBox Manager | |
Select your Docker Machine VirtualBox image (e.g.: default) | |
Open Settings -> Network -> Advanced -> Port Forwarding | |
Add your app name, the desired host port and your guest port | |
docker-machine start default | |
eval $(docker-machine env default) | |
docker-machine url | |
docker images > see list of images thats on local machine | |
docker images --all | |
docker ps -a # shows all container even not running | |
docker ps # see all container; or docker container ps | |
docker container stop mysql # stop the container | |
docker container rm myapache # remove container | |
docker container rm myapache -f # forced removal if its running | |
docker container exec -it mynginx bash # tunnel into container | |
docker start mynginx # start up a container | |
docker rm $(docker ps -aq) -f # force remove all containers | |
Dockerfile | |
FROM nginx:latest | |
WORKDIR /usr/share/nginx/html | |
COPY . . | |
docker image build -t mynginxinit . | |
docker images | |
# remove docker and start again | |
docker rm $(docker ps -aq) -f | |
docker container run -d -p 8080:80 --name mynginx mynginxinit | |
docker cp mynginx:/usr/share/nginx/html/ c:\\Users\\docker\\nginx2 | |
# docker cp c:\Users\docker\nginx2 mynginx:/usr/share/nginx/html/ | |
// give yourself full permission to access folder on your windowns 7 local machine | |
docker cp mynginx:/usr/share/nginx/html/ c:\\Users\\docker\\nginx2 | |
docker rm $(docker ps -aq) -f | |
docker container run -d -p 8080:80 -v /c/Users/docker/nginx2:/usr/share/nginx/html --name mynginx mynginxinit | |
cd c:/users/docker/nginx2 | |
code . | |
docker container exec -it mynginx bash | |
cd /usr/share/nginx/html | |
apt update | |
apt install nano | |
apt-get install nano | |
nano index.html | |
# Map docker local folder to your localmachine | |
# bind mount | |
- docker nginx is debian image | |
- cd usr/share/nginx/html | |
- cd to your windows folder | |
docker container run -d -p 8080:80 -v $(pwd):/usr/share/nginx/html --name mynginx nginx | |
docker container run -d -p 8080:80 -v /C/docker/nginx:/usr/share/nginx/html --name mynginx nginx | |
docker container run -d -p 8080:80 -v /c/Users/nginx:/usr/share/nginx/html --name mynginx nginx | |
code . # open visual studio code in directory that youre in | |
winpty docker container exec -it mynginx bash | |
apt-get update && apt-get install procps -y | |
ps -ef | grep nginx | |
cd /usr/share/nginx && chown -R nginx:nginx * | |
apt-get install nano | |
docker container exec -it nginx-website bash | |
docker container run -d -p 8080:80 -v C:\docker\nginx | |
List of docker commands: | |
https://gist.github.com/bradtraversy/89fad226dc058a41b596d586022a9bd3 | |
https://medium.com/@nagarwal/lifecycle-of-docker-container-d2da9f85959 | |
docker-machine ip default | |
docker info | |
docker container ls > shows running container | |
docker container ls -a > shows all container | |
docker container rm idOfContainer > removes a container | |
docker pull nginx > gets image nginx from docker | |
docker container run -d -p 8080:80 --name mynginx nginx | |
# d for detach to run in background; name custom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment