Tools, FAQ, Tutorials:
"docker container run" - Create Container with New Command
How to Create a new Container with a New Command using the "docker container run" command?
✍: FYIcenter.com
If you want to create an Alpine container that starts with a new command different than the default command, you need to use the "docker container run" command with your Linux command specified.
1. Create a new container with "alpine" image and start it with "ping google.com" running in the container.
fyicenter$ docker container run --name 2nd_alpine alpine ping google.com PING google.com (172.217.7.174): 56 data bytes 64 bytes from 172.217.7.174: seq=0 ttl=49 time=1.941 ms 64 bytes from 172.217.7.174: seq=1 ttl=49 time=1.829 ms 64 bytes from 172.217.7.174: seq=2 ttl=49 time=2.203 ms 64 bytes from 172.217.7.174: seq=3 ttl=49 time=1.741 ms 64 bytes from 172.217.7.174: seq=4 ttl=49 time=1.814 ms 64 bytes from 172.217.7.174: seq=5 ttl=49 time=1.830 ms ^C --- google.com ping statistics --- 15 packets transmitted, 15 packets received, 0% packet loss round-trip min/avg/max = 1.682/1.907/2.615 ms fyicenter$
2. Check the container status.
fyicenter$ docker container list --latest CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES fddc7452d4f6 alpine "ping google.com" About a minute ago Exited (0) 5 seconds ago 2nd_alpine
As you can see, the new container was started with the "ping google.com" command. Its console is attached to my hosting console. That's why I can see the "ping" output.
You can press Ctrl-C to terminate the "ping" command. But that also ends the execution of the container.
But the console output of the container execution is still maintained in the container. You can fetch it with the "docker container logs" command.
⇒ "docker container run --detached" - Run Container in Background
2019-02-06, 1091🔥, 0💬
Popular Posts:
Where Is the Submitted Form Data Stored in PHP? When a user submit a form on your Web server, user e...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
How to add a new operation to an API on the Publisher Dashboard of an Azure API Management Service? ...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...