Friday, April 7, 2017

Docker From the Ground Up: Working With Containers, Part 2

This is part two of a two-part series about working with Docker containers. In part one, we focused on the many ways and options to run an image and how the host can interact with a Docker container. 

In this part, we'll cover listing, starting, stopping and restarting containers as well as executing commands on running containers. In particular, you'll learn the difference between running and stopped (exited) containers, and how to control precisely the information and display when you list your containers by filtering and formatting. 

Then, you'll get hands-on experience stopping, starting, restarting and attaching to your containers. Finally, you'll run one-off commands as well as gain interactive shell access to a running container. 

Before we start, make sure that Docker is installed properly in your environment. Depending on how it installed and your user, you may need to run it as sudo. I'll skip the sudo. 

Listing Containers

When working with containers, you often want to list, view and filter your containers. The docker ps command is the key, and it has several interesting options.

Running Containers

The most basic command is plain docker ps with no arguments, which shows all the currently running containers.

You get a lot of information on each container, including the container id, the image, the command, when it was created, its current status, its ports, and its names. It's a little difficult to parse due to the wrapping. We'll see later how to filter and format the output. Note that the command is truncated (as well as the container id). To show the full command, add --no-trunc:

Now, the full command is visible: nginx -g 'daemon off;'

All Containers

As you recall, Docker keeps stopped containers around (unless you ran them with --rm). Adding -a shows all containers:

Formatting

The output of docker ps can be too verbose and often shows a lot of fields that are not interesting. You can use Go-template formatting to display just the fields you're interested in. Here is showing just the name and the command:

That works, but to present it with the field names, add "table" to the beginning of the format string:

The format name for the container id (not selected here) is (all caps).

Filtering

The docker ps command supports many filters. They are pretty straightforward to use. The syntax is -f "<filter>=<value>". Supported filters are id, label, name, exited, status, ancestor, before, since, isolation, network, and health.

Here is filtering by container name and showing only the busybox container:

The -q Flag

If all you want is the container id, use the -q flag (quiet flag). It's simpler than --format 'table '. This is often needed when you want to perform operations on multiple containers (you'll see an example later).

Stopping, Starting, and Restarting Containers

You can stop running containers and start a stopped container. There are several differences between starting a stopped container and running a new instance of the same image:

  • You use the same environment variables, volumes, ports and other arguments of the original run command.
  • You don't have to create yet another container.
  • If the stopped instance modified its file system, the started container will use the same.

Let's stop the nginx container and then start it. When you refer to a container, you can use its name or an unambiguous prefix of its id. I usually name my long-running containers so I have a meaningful handle and don't have to deal with Docker's auto-generated names or containers' id prefixes.

OK. Nginx is stopped (status is "Exited"). Let's start it:

Restarting a running container is another option, which is equivalent to docker stop followed by docker start.

$ docker restart nginx

Attaching to a Running Container

When you start a stopped container, or if you ran your container in detached mode (-d command-line argument), you can't see the output. But you can attach to it.

Removing Containers

You can remove stopped containers with the command:  docker rm <container id or name>

If you want to remove a running container, you can either stop it first or use the -f (force) command-line argument:

If you want to remove all containers, here is a nice snippet:

docker rm -f $(docker ps -aq)

If you want to remove just the stopped container, remove the -f (force) flag.

Executing a Command Inside a Running Container

Docker runs a single process inside a container, but you can execute additional commands against a running container. It is very similar to providing a custom command to the docker run command, except that in this case it is running side by side with the run command.

Simple Commands

Running a simple command is done via docker exec. You provide a running container id or name and the command you wish to execute. Let's check out the nginx.conf file inside the nginx container and see how many worker processes are configured.

Interactive Shell

One of the best troubleshooting techniques with Docker containers is to connect to an interactive shell and just explore the internal file system. In order to attach stdin and have a tty, you need to provide the -i -t command-line arguments (can be grouped as -it) and then the name of a shell executable (usually bash). 

You end up with shell access to your container. Here is an example of checking the worker processes interactively from "inside" the container.

Conclusion

Docker is a powerful platform, and since the container is its unit of work, it provides a lot of tools to manage and work with containers. I described most of the important aspects of working with containers, but there are many more advanced features, options and nuances to the commands I covered, as well some additional commands. 

If you work closely with Docker containers, take the time to dive in and learn all about them. It will pay off handsomely.


by Gigi Sayfan via Envato Tuts+ Code

Quick Tip: Create Autosizing Text with Android O

#329: An opinionated comparison of React, Angular and Aurelia

Regexes in a post-ES6 world, and why Glimmer is so fantastic.Read this e-mail on the Web
JavaScript Weekly
Issue 329 — April 7, 2017

We found too many releases were happening on Thursdays so JavaScript Weekly has moved back to Fridays :-) We're also working on a redesign and would love if you could anonymously share your opinions here - all feedback welcomed.
- Peter Cooper, editor

A look at new regex features introduced in ES6 or later, including the y, u and s flags, named capture groups, and look-behind assertions.
Nicolás Bevacqua

A practical, code-led look at how Glimmer provides the benefits of Ember’s fast rendering engine and sturdy tools without having to buy into the whole ecosystem.
Tristan Edwards

Opinion pieces are a dime-a-dozen but this shows some real insight and technical considerations. It also spawned a Hacker News discussion.
Jeff Schnitzer

Frontend Masters
A free, thorough and open source guide anyone could use to learn about the practice of front-end development.
Frontend Masters   Sponsor

Facebook merged a huge pull request into React that replaced its build process with one based on Rollup and not Webpack. But why?
Rich Harris

A fast 3KB React alternative with the same API. 8.0 boasts significant performance improvements, smaller size, and fewer edge cases. 8.0.1 is the latest release.
Jason Miller

A cross-platform app including a simulator and integrated Node server.
Bita Djaghouri, Jin Choi, Mark Marcelo

It's in Chrome Canary only for now, but it shows you which lines were and weren’t used in each JavaScript and CSS file.
LogRocket

Jobs Supported by Hired.com

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

EmberConf 2017: State of the Union news
Now 5 years old, a look at both Ember’s history and future.
Tom Dale, Yehuda Katz, Godfrey Chan

Angular Attack: A 48-Hour Online Angular Hackathon (April 22-23) news
Angular Attack

How 3575 Developers Debug Their Front-End JavaScript 
console.log wins but is less popular than in a similar poll a year ago.
Twitter

Easily Add GIFs to Any Realtime Chat App tutorial
You can’t hide from them. GIFs are everywhere. Easily add Giphy GIFs to your app.
PubNub  Sponsor

Everything You Need to Know About Change Detection in Angular tutorial
Maxim Koretskyi

11 Ways to Invoke a Function tutorial
Think of any more? Leave a comment.
Alexander Myshov

Using Pipes in Angular tutorial
How to use the new pipes functionality that replaces filters from Angular 1.
Burke Holland

How to Deal with Unhandled Promise Rejections tutorial node
Valeri Karpov

How to Create a (Very Simple) Reddit Client with Angular 4 tutorial
Ashraff Hathibelagal

Build More & Save More with API Mocking 
Sandbox - API Mocking Software  Sponsor

Why You Should Make Desktop Apps with Electron (in 5 Minutes) video
Matt Andrews

Brendan Eich Talks WebAssembly podcast
Brendan Eich on his involvement with the WebAssembly specification. 1h24m.
Software Engineering Daily

JavaScript Frameworks: A Futile Attempt At Objectivity opinion
A personal view of the current state of JavaScript frameworks.
Matt Burgess

eslint-plugin-security: ESLint Rules for Node Security tools node
Helps to identify potential security hotspots.
The Node Security Platform

Adaptive Live and VoD 360 Streaming in HTML5 on Desktop and Mobile tools
Stream your VR and 360 video with Netflix quality to all major devices using adaptive streaming (DASH and HLS).
Bitmovin  Sponsor

Tippy.js: A Fancier but Pure JS Tooltip Library code
Extends Popper.js (featured last week) with theming, effects, & support for complex popovers.
atomiks

Embedo: A Modern Social Media Embed Plugin code
For Facebook, Twitter, Instagram, YouTube and Pinterest content.
Shobhit Sharma

SweetAlert2: An Accessible (WAI-ARIA) Replacement for JS Alerts code

BitArray.js: A Memory Efficient Implementation of Bit Flag Arrays code
Packs booleans into Uint32Arrays for efficiency.
Brock Whittaker

Glamorous: React Component Styling Solved code
PayPal

UTIF.js: A Small and Fast TIFF Decoder in Pure JS code
TIFF is an arcane yet still encountered image format.
Photopea

Curated by Peter Cooper and published by Cooperpress.

Like this? You may also enjoy: FrontEnd Focus : Node Weekly : React Status

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooperpress Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly

Docker From the Ground Up: Working With Containers, Part 1

This is part one of a two-part series about working with Docker containers. In this part, we'll focus on the many ways and options to run an image and how the host can interact with a Docker container. 

In the second part we'll cover listing, starting, stopping and restarting containers as well as executing commands on running containers. Docker images are the units of deployment. When you run an image, you instantiate a Docker container that runs a single process in its own isolated environment for the file system, networking and processes tree. 

Docker containers are very flexible and enable many use cases that are too heavyweight, complex and/or expensive with other technologies like virtual machines and bare metal servers.

Before we start, make sure that Docker is installed properly in your environment. Depending on how it installed and your user, you may need to run it as sudo. I'll skip the sudo. 

Running an Image

You launch a Docker container by running an image. There are several ways to run a container that affect how easy it is to manage all the containers. When the container starts, it typically runs the command defined in the Dockerfile. Here is the Dockerfile for the hello-world container:

The command simply runs the "hello" binary that was copied to the root of the container when building the image.

Foreground vs. Detached

A container can run in the foreground where it blocks until the process exits and the container stops running. In foreground mode, the container prints its output to the console and can read standard input. In detached mode (when you provide the -d flag), control returns immediately and the container 

Running an Unnamed Container

The simplest way to run a container is: docker run <image id or name>.

When you run a container using this command, Docker will assign it a name composed of two random words. For example: docker run hello-world.

If you already have the hello-world image then Docker will run it. If you don't, it will pull it from the official Docker repository DockerHub and then run it. The output should look like:

The hello program exits after displaying the message, which terminates the process running inside the container and ends the container run. The container still sticks around in case you want to connect to it, examine logs, or anything else. To view the container, you can run the following command:

I'll explain later how to list containers and all the relevant options. For now, let's focus on the Names section. Docker generated the name "clever_liskov" automatically, and I'll have to use it or the container ID to refer to this container for any purpose like restarting it, removing it, or executing a command.

Running a Named Container

Using container IDs or auto-generated names is sometimes inconvenient. If you interact frequently with a container you re-create frequently, then it will get a different ID and auto-generated name. Also, the name will be random. 

Docker lets you name your containers when you run them by providing a "--name <container name>" command-line argument. In simple cases, where you have just one container per image, you can name the container after your image: docker run --name hello-world hello-world.

Now, if we look at the process (I removed clever_liskov earlier) we'll see that the container is named hello-world:

There are several benefits to a named container:

  • You have a stable name for your containers you use both interactively and in scripts.
  • You can choose a meaningful name.
  • You can choose a short name for convenience when working interactively.
  • It prevents you from accidentally having multiple containers of the same image (as long as you always provide the same name).

Let's look at the last option. If I try to run the same run command again with the same "hello-world" name, I get a clear error message:

Running an Auto-Remove Image

Containers stick around by default. Sometimes, you don't need them. Instead of manually removing exited containers, you make the container go away on its own. The --rm command-line argument does the trick: docker run --rm hello-world.

Running a Different Command

By default, Docker runs the command specified in the Dockerfile used to build the image (or directly the entry-point if no command is found). You can always override it by providing your own command at the end of the run command. Let's run ls -la on the busybox image (the hello-world image has no ls executable):

Interacting With the Host

Docker containers run isolated processes in their own little world. But it is often necessary and useful to provide access to the host.

Passing Environment Variables to a Container

Docker containers don't automatically inherit the environment of the host process that ran them. You need to explicitly provide environment variables to the container when you run it using the -e command-line flag. You can pass multiple environment variables. Here is an example: 

The first line runs the busybox container, passing it the ENV_FROM_HOST variable and then inside the container running env shows that the ENV_FROM_HOST is properly set.

You can use host environment variables too. This sets a couple of host environment variables and uses them in the run command:

Inside the container, they are now visible:

Mounting Host Directories

One of the most useful interactions is mounting host directories. That allows several interesting use cases:

  • Shared storage between containers running on the same host.
  • Viewing and editing files using your host environment and tools and using the files in the container.
  • Host-level persistence beyond the lifetime of a container.

Here I create a file on the host: $ echo "Yeah, it works!" > ~/data/1.txt

Then I run the busybox image mounting the ~/data directory to /data in the container and displaying the file contents on the screen:

I used the cat /data/1.txt command here.

Exposing Ports to the Host

If you expose a port in your Dockerfile using EXPOSE, it will be accessible only to other docker containers. To make it accessible on the host, you need to use the -p command-line argument. The syntax is -p <host port>:<exposed container port>.

Here is running the nginx image, which exposes port 80 and uses the -p command-line argument to make it visible on the host on port 9000: 

Note that unlike the previous commands that performed some tasks and completed, the nginx container will keep running and listening to incoming requests. Let's verify that nginx is really up and running and responds to requests on port 9000. I prefer the excellent httpie HTTP client over curl for hitting web servers and services from the command line:

Conclusion

There are many ways to run a Docker image to create a container, and there are many options. Each combination supports a particular use. It is very useful when working with Docker containers to fully grasp the details and use the best method to launch your containers. 

In addition, attaching host volumes and exposing and publishing ports allows tight integration with the host and a plethora of use scenarios. In part two, we'll dive into managing a bunch of containers and taking advantage of the full power Docker provides.


by Gigi Sayfan via Envato Tuts+ Code

Victoire Douy — Portfolio

Victoire Douy UIUX designer based in Paris and student at Gobelins school of the image
by via Awwwards - Sites of the day

Live Video: Tips and Techniques for Creating Great Content

Do you broadcast live video? Want to learn how to create an engaged following? To discover what he’s learned from broadcasting over 1,000 live streams over the last two years, I interview Alex Khan. More About This Show The Social Media Marketing podcast is an on-demand talk radio show from Social Media Examiner. It’s designed [...]

This post Live Video: Tips and Techniques for Creating Great Content first appeared on .
- Your Guide to the Social Media Jungle


by Michael Stelzner via

Thursday, April 6, 2017

Relational and Attribute Selectors in CSS3

The following is an extract from our book, HTML5 & CSS3 for the Real World, 2nd Edition, written by Alexis Goldstein, Louis Lazaris, and Estelle Weyl. Copies are sold in stores worldwide, or you can buy it in ebook form here.

[author_more]

CSS3 Selectors

Selectors are at the heart of CSS. Without selectors to target elements on the page, the only way to modify the CSS properties of an element would be to use the element’s style attribute and declare the styles inline, which is awkward and unmaintainable. So we use selectors. Originally, CSS allowed the matching of elements by type, class, and/or ID. This required adding class and ID attributes to our markup to create hooks and differentiates between elements of the same type. CSS2.1 added pseudo-elements, pseudo-classes, and combinators. With CSS3, we can target almost any element on the page with a wide range of selectors.

In the descriptions that follow, we’ll be including the selectors provided to us in earlier versions of CSS. They are included because, while we can use CSS3 selectors, selectors that predate CSS3 are also part of the CSS Selectors Level 3 specification and are still supported, as CSS Selectors Level 3 expands on them. Even for those selectors that have been around for quite some time, it’s worth going over them here, as there are some hidden gems in the old spec that few developers know. Note that all modern browsers, including IE9 and above, support all CSS3 selectors.

Continue reading %Relational and Attribute Selectors in CSS3%


by Alexis Goldstein via SitePoint