Skip to content

Instantly share code, notes, and snippets.

@masterkawaster
Last active June 17, 2019 12:04
Show Gist options
  • Save masterkawaster/ec987e12363808f97a7b0679b40871a6 to your computer and use it in GitHub Desktop.
Save masterkawaster/ec987e12363808f97a7b0679b40871a6 to your computer and use it in GitHub Desktop.
docker commands on windows
#visual studio in docker container:
https://blogs.msdn.microsoft.com/heaths/2017/09/18/installing-build-tools-for-visual-studio-2017-in-a-docker-container/
#private registry
https://hub.docker.com/r/stefanscherer/registry-windows/
#to build image run inside the project dir (where Dockerfile is):
docker build . -t <image_name>
#to build without cache and to specify custom dockerfile:
docker build --no-cache -t <image_name> -f <dockerfile> .
#Copy to docker container (stopped container):
push-location ./site
docker cp . <container_name>:c:/inetpub/wwwroot
pop-location
#files need to be in context. by default everything is in context what is in docker file directory. to specify what's not do it in docker.ignore.
#It's good to define copy with two lines:
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
#to show existing images in repo:
docker images
#to list running containers:
docker ps
#to list container names:
docker ps --format "{{.Names}}"
#to list all created containers:
docker ps -a
#to show container details:
docker inspect <container_id>
docker inspect -f "{{.NetworkSettings.Networks.nat.IPAddress}}" <container_name>
#to list networks
docker network ls
#to find container ip
docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" <container_name_taken_from_last_column_of_docker_ps>
#to run image:
docker run -i -t <image_id> /bin/bash
#pass variables with prefix:
docker run -it --rm --env-file <(env | grep XDG) alpine sh
#to remove container after stop just add --rm
docker run --rm my-docker
#stop container
docker stop <container_id>
#list all containers
docker container ls -f 'status=exited'
#start container
docker container start <container_name>
#to connect from inside container to docker host use dns name
docker.for.win.localhost
#docker compose (do it all) (create container)
docker-compose up -d
#docker compose and rebuild image
docker-compose up --build
#docker compose, rebuild image and recreate container, run in detached mode (-d)
docker-compose up --build --force-recreate -d
#exposed port:
- in docker-compose.yml put ports
<exposed_port>:<port_of_application>
- ipconfig to see your machine ip
- you should be able to connect to: <your_machine_ip>:<exposed_port>
localhost does not work for some reason
#configs and secrets in docker swarm:
https://docs.docker.com/engine/swarm/configs/#advanced-example-use-configs-with-a-nginx-service
#networks:
#transparent for direct access to host's adapter
#nat - needs port mapping and connection through host
docker network create -d transparent mytransparentnet
#set then network in docker compose file.
#connect to container's powershell (full container id is that long long sha from docker inspect):
docker exec -ti <full_container_id> powershell
#to list env variables inside container:
ls env:\
#to show file content:
type <file_name>
#example docker-compose.yml
version: '3'
services:
webapplication1:
ports:
- 8081:80
environment:
- ASPNETCORE_ENVIRONMENT=Development
image: webapp
build:
context: ./WebApplication1
dockerfile: Dockerfile
networks:
default:
external:
name: nat
#docker-compose.ci.build.yml
version: '2'
services:
ci-build:
image: microsoft/aspnetcore-build:1.0-1.1
volumes:
- .:/src
working_dir: /src
command: /bin/bash -c "dotnet restore .<solution_name>.sln && dotnet publish ./<solution_name>.sln -c Release -o ./obj/Docker/publish"
#docker file (Dockerfile):
FROM microsoft/aspnetcore:1.1
WORKDIR /app
EXPOSE 80
COPY PublishOutput .
ENTRYPOINT ["dotnet", "<target_dll>.dll"]
#Delete from docker ignore as nothing will be deployed!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment