Handling your running containers with Docker cmdlets

If you need to get a PowerShell session into a running container, you have two options:

  • First, you can use Enter-PSSession, as if you were connecting to another computer, except you need to give it the full ID of the container instead of the machine name. The easiest way to get there is to use a subcommand querying Docker for that container. Entering a PS session for the mycontainer container would look like this:
Enter-PSSession -containerid (docker --no-trunc -qf "name=mycontainer")

The preceding statement only works when you're running as an administrator.

  • The second option is to execute the powershell command on your container and instruct Docker to open an interactive Terminal for it. This would look as follows for the mycontainer container:
docker exec -ti mycontainer powershell

With both commands, you end up with a PowerShell session inside your container. If you want to run Business Central cmdlets, the easiest way is to call c: unprompt.ps1, which imports all the development and admin cmdlets.

To see all the currently running containers, you can write and execute docker ps, which gives you the following output:

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12cec5da3d89 mcr.microsoft.com/businesscentral/sandbox "powershell -Comma..." 22 minutes ago Up 21 minutes (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp determined_shockley
9518e7e456de mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." 42 minutes ago Up 41 minutes (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp testcont
95959a311e54 mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." About an hour ago Up About an hour (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp RKOS-18111
13057bf415cc mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." 22 hours ago Up 22 hours (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp VOEKOM
0e7970ce5318 mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." 29 hours ago Up 29 hours (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp Buchau
6c1c44f170bb mcr.microsoft.com/dynamicsnav:2017-cu22-at "powershell -Comma..." 46 hours ago Up 46 hours (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp syAToekom

To see all currently existing containers, you can use docker ps -a, which also includes exited and/or stopped containers (the output also shows a container with a status of Exited):

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
12cec5da3d89 mcr.microsoft.com/businesscentral/sandbox "powershell -Comma..." 24 minutes ago Exited (1073807364) 9 seconds ago determined_shockley
9518e7e456de mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." 43 minutes ago Up 43 minutes (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp testcont
95959a311e54 mcr.microsoft.com/dynamicsnav:2017-cu22-de "powershell -Comma..." About an hour ago Up About an hour (healthy) 80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp RKOS-18111

Stopping and starting containers is as easy as using docker stop and docker start, respectively. If you want to remove a container, you need to either stop (docker stop) and then remove it (docker rm) or use the -f parameter for docker rm to force the removal of the container, even if it's still running.

Be aware that removing a container means that all the files inside that container are gone and can't be restored.

If the command is successful, it only returns the name or ID of the container as you specified it:

docker rm -f 12

Note that you can address containers either with their name or with their ID. You don't need to specify the full ID; you just need enough characters from the beginning of the ID so that Docker can uniquely identify the container. Also, note that docker ps gives you a truncated ID for each container, and you can use docker ps –no-trunc to get the full ID.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.198.49