Skip to content

arp6333/ConsoleApplicationInDocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Hosting a Console Application in Docker

Set-up

  1. Download and install Docker.

  2. Login and switch to Windows Containers.

    Switch to Windows Containers

  3. Go to Windows 'System Information' (Start -> System Information) and retrieve the version of Windows you are using under 'Version'.

    System Information

  4. Search for your Windows version on Microsoft's Windows Server Core Images section for using the correct image. For example, my version is 17134 so I search for 17134:

    Windows Version

  5. Any tag on the left most column can be used as long as the OsVersion lines up with your computer's version, for this example I use the tag '1803' as it was the simplest one and lined up with my version of 17134. You must use the correct tag otherwise it will fail to pull the image.

  6. If you do not need to run the container on a set Ip Address, skip the Docker Network step and omit the --network and --ip options during container creation.

Create the Docker Network

If you do not need to run the container on a set Ip Address, skip this step and omit the --network and --ip options during container creation.

The command to create a docker network is:

docker network create -d transparent --subnet=<subnet> --gateway=<gateway> <network name>

For example:

docker network create -d transparent --subnet=192.168.1.0/25 --gateway=192.168.1.100 Network

Create the Container

If you do not need to run the container on a set Ip Address, omit the --network and --ip options. If you do, make sure you do the Docker Network step above first.

The command to create the container is:

docker run -it --name <container name> --network=<network name> --ip <ip> mcr.microsoft.com/windows/servercore:<servercore version>

To get your servercore version, see Set-up.

For example:

docker run -it --name container --network=Network --ip 192.168.1.22 mcr.microsoft.com/windows/servercore:1803

Running the Container with Powershell

The command to starting running the container with Powershell is:

docker exec -it <container name> powershell

If you get an error that the container is not running, start the container:

docker start <container name>

Start a Console Application in the Container

Copy all files needed to run the application into the docker container, then run the executable.

  1. From inside the docker container, create a directory to contain all the files needed:

    mkdir Application
  2. Close the container and then stop it from the host:

    docker stop <container name>
  3. Move all files into the container from the solution's /bin/Release directory (or /bin/Debug if you do not have a Release). It is easiest to enter the directory, then move all files to your newly created directory in the container (make sure to put the path in quotations ("") if there are spaces in it during the copy command):

    cd <path to your solution>/bin/Release
    docker cp . <container name>:C:/Application

    If you ever get a "filesystem operations against a running container are not supported" error, then make sure to stop the container (see step 2 above).

  4. Start and re-enter your container (see the Running the Container with Powershell step above).

  5. From inside the container, navigate to your directory and check if all files were added:

    cd Application
    ls
  6. Run the executable for your solution:

    ./Application.exe

Other useful commands

Show all containers (remove the -a to only show running ones)

docker container ls -a

Remove a container

docker rm <container name>

Rename a container

docker rename <current container name> <new container name>

About

Hosting a Console Application in Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors