Home > Software design >  How to test Docker container on another machine?
How to test Docker container on another machine?

Time:05-19

Im still new with docker and the concept of containers. So i wrote a simple script as follows:

#main.py
def test_function():
  val=input('please enter a number')
  for i in range(int(val)):
     print (i)

i docerkize it and put in in a container and ran it from there and everything is working fine.

I have another machine with linux os, how can i test this container there? do i simply copy paste it there? or how should i do it?

Im learning by implementing and trying to find answers by trying, so this might a basic question but im missing the idea

CodePudding user response:

You need to install Docker on the other machine, and then push the image to a docker registry (e.g dockerhub / AWS ECR).

I use ECR. You need to create a registry and then tag your docker image with the url of the registry by running docker tag <source image> <url of the registry>, then run docker push <image name>

and to pull it from the other machine, run docker pull <url of the rigistry>

Or, you could just simply install docker on the other machine, copy the dockerfile there, and run docker build -t <image name> /path/to/file

CodePudding user response:

There are several abstractions, which you should take use of:

  • language abstraction (python in your case)
  • os abstractions (docker in your case)
  • api abstraction (stdout in your case)

When it comes to simple functions like yours, there is no reason to test dockerized application twice because docker handles os abstraction very well, and makes your container environment independent (most of the times).

For your function, you should change output from stdout to other source, and test data, you are putting there with unit test.

You should do it using same language, and it's libraries (like PyTest).

  • Related