Setting up a Docker container
April 23, 2022My quick reference guide on setting up and configuring a Docker container. Includes some notes on Azure Docker, too!
The motivation behind experimenting with Docker and Azure was myself attempting to get custom exectuables to be called when new files arrive in a Azure Storage Container. Thought was that when a new file appears, there may be a mechanism to trigger an executable within a Docker container. However the vast majority of application Docker container examples are for web-applications where the state is relatively persistent within the container itself.
For instance, web pages and a associated database can all reside in the container, under it’s own “ecosystem”. Whereas, my intent was my custom application resides within a container, access’ an external file (in Microsoft storage), executable does some data transformation on the file, and writes back externally to Microsoft storage. My research indicates this really isn’t the best use case for a Docker container and instead a mere Virtual Machine is better suited, using a tool such as inotifywait instead - with the Microsoft storage mounted in the virutal machine as a drive.
Great documentation
Complete Docker documentation can be found below, and is very thorough.
https://docs.docker.com/engine/reference/commandline/docker/
getting an image from docker hub
docker pull tatsushid/tinycore:11.0-x86
list images
sudo docker images
where it’s all saved
cd /var/lib/docker
run in interactive mode
docker run -it foo
- foo can be REPOSITORY:TAG (if tag is ommited, it is replaced with latest)*
- or, food can be the IMAGE ID
detach from container (in interactive)
In the shell, type ctrl+p then ctrl+q
get list of running containers
sudo docker container ls
attach to a running container
sudo docker container attach [CONTAINER_ID]
restart a container
sudo docker container restart v-container
kill a container
sudo docker kill CONTAINER_ID
run in daemon mode
docker run -d foo
display list of launched containers
sudo docker ps
(add -a flag for all)
saving changes
- sudo docker ps -a
- take note of the CONTAINER ID
- sudo docker commit CONTAINER_ID new_image_name
- can now see with
sudo docker images
save image to tar archive
- docker save [OPTIONS] IMAGE [IMAGE…]
- for example: docker save -o fedora-latest.tar fedora:latest
- run with docker load
File copying
copying single file to the container
docker cp foo.txt container_id:/foo.txt
copying single file from the container
docker cp container_id:/foo.txt foo.txt
copying multiple files
docker cp src_folder/ container_id:/target
docker cp container_id:/src/. target
tinycore linux specific image
https://hub.docker.com/r/bensuperpc/tinycore
Some tinycore essentials to install:
tce-load -wic bash.tcz binutils.tcz gcc.tcz nano.tcz git.tcz make.tcz compiletc.tcz openssh.tcz
Deploying image to Azure
-
In portal.azure.com, create a Container Registry
- On Access Keys blade, enable Admin User
-
On dev machine,
sudo docker login paranreg.azurecr.io
- login and password is in the Access Keys on the blade
- be sure to run as sudo, or get permission errors
-
sudo docker push paranreg.azurecr.io/tcparan:latest
- Under the Repositories on the blade, tcparan will now be there.
-
Create a Container Instance, select the container from above.
- Be sure proper ports open on Networking tab.
- Once the container instance is created, be sure to Start it.