Some useful Docker commands

in #technology6 years ago (edited)

Lately I've been using Docker quite often and loving it, as it makes it really simple to deploy applications. Today I will discuss some useful Docker commands that are handy.


image source

1. Docker exec

Let us say you are running a docker container in detached mode, you can still directly execute commands on it, using docker exec. For example, if you want to open a file using vim in docker for editing it, you can issue the following command.

docker exec -it container_name sh -c 'vi somedirinsidedocker/somefile.txt'

2. Docker container start

If for some reason you want to stop a container for a moment, you can restart it by using this command. For stopping a container you use docker stop container_name, while for restarting it, you would use docker container start container_name.

3. Docker inspect

You can use this command to get all the details about a container, such as its IP Address for example. The syntax is docker inspect container_name. If you want to see a specific attribute, you can use grep for filtering it out. For example, for knowing the IP address, we would use docker inspect container_name | grep IPAddress.

4. Docker cp

With this command, you can copy files/folders between host and the container. To copy from host to container, use docker cp file_or_folder_on_host container_name:destination_folder_on_container. To copy from container to host, use docker cp container_name:file_or_folder_on_container destination_folder_on_host.

5. Docker rename

This command renames a container. Example usage is docker rename old_name new_name.

For the full list of commands, you can visit https://docs.docker.com/engine/reference/commandline/docker/.

Sort:  

very useful article.

As a follower of @followforupvotes this post has been randomly selected and upvoted! Enjoy your upvote and have a great day!

i think you got something wrong with your docker start command. shouldnt it be just "docker start container_name"?